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.