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.