QOJ.ac

QOJ

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

#20940. Балансировка инверсий

Statistics

Bessie и Elsie играли на булевом массиве $A$ длины $2N$ ($1 \leq N \leq 10^5$). Очки Bessie — число инверсий в первой половине $A$, а очки Elsie — во второй половине $A$. Инверсия — пара элементов $A[i]=1$ и $A[j]=0$, где $i<j$. Например, блок нулей, за которым идёт блок единиц, не имеет инверсий; блок из $X$ единиц, за которым идут $Y$ нулей, имеет $XY$ инверсий.

Farmer John случайно нашёл игровое поле и хочет знать минимальное число обменов соседних элементов, после которых игра выглядела бы ничьей. Помогите ему найти ответ.

Входные данные

Первая строка содержит $N$, следующая — $2N$ целых, каждое равно нулю или единице.

Выходные данные

Выведите число соседних обменов, необходимых для ничьей.

Примеры

Входные данные 1

5
0 0 0 1 0 1 0 0 0 1

Выходные данные 1

1

Примечание

В примере первая половина изначально имеет $1$ инверсию, вторая — $3$. После обмена $5$-го и $6$-го битов обе половины имеют $0$ инверсий.

Автор задачи: 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.