QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20940. Cân bằng nghịch thế

Statistics

Bessie và Elsie chơi trên mảng boolean $A$ dài $2N$ ($1 \leq N \leq 10^5$). Điểm của Bessie là số nghịch thế ở nửa đầu $A$, còn điểm Elsie ở nửa sau của $A$. Một nghịch thế là cặp phần tử $A[i]=1$ và $A[j]=0$ với $i<j$. Ví dụ, một khối số không theo sau bởi khối số một không có nghịch thế; khối $X$ số một theo sau bởi $Y$ số không có $XY$ nghịch thế.

Farmer John tình cờ thấy bàn chơi và muốn biết số lần đổi chỗ hai phần tử kề nhau ít nhất để trò chơi trông như hòa. Hãy giúp ông tìm đáp án.

Dữ liệu vào

Dòng đầu chứa $N$, dòng tiếp chứa $2N$ số nguyên bằng không hoặc một.

Dữ liệu ra

In số lần đổi chỗ kề nhau cần thiết để hòa.

Ví dụ

Dữ liệu vào 1

5
0 0 0 1 0 1 0 0 0 1

Dữ liệu ra 1

1

Ghi chú

Trong ví dụ, nửa đầu ban đầu có $1$ nghịch thế, nửa sau có $3$. Sau khi đổi chỗ các bit thứ $5$ và $6$, cả hai mảng con có $0$ nghịch thế.

Tác giả bài toán: Dhruv Rohatgi

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.