QOJ.ac

QOJ

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

#22310. פרות סועדות (ארד)

Statistics

הפרות בררניות מאוד לגבי שותפות לארוחה. הן נחלקו לקבוצות $1$ ו-$2$ ומתעקשות לסעוד יחד לפי סדר, $1$ בתחילת התור ו-$2$ בסופו. הבעיה מתחילה כשהן עומדות ליד האסם להיכנס לאזור ההאכלה.

כל פרה $i$ נושאת כרטיס עם $D_{i}$ ($1 \le D_{i} \le 2$), קבוצתה. כל $N$ הפרות ($1 \le N \le 30{,}000$) בתור, אך ברור שאינן מקובצות לפי הכרטיסים.

עבודת FJ קלה: ללכת לאורך התור, למחוק מספר ישן ולכתוב חדש לשינוי קבוצה. כך מתקבלים רצפים עולים כמו 112222 או 111122. לעיתים נותרת קבוצה אחת, למשל 1111 או 222.

FJ עצלן כמו אחרים. מהו מספר הכרטיסים המזערי לשינוי כדי לקבץ נכון? מותר לשנות מספרים בלבד, אסור לסדר מחדש את הפרות.

קלט

קראו מהקלט הסטנדרטי.

  • שורה 1: שלם $N$.
  • שורות $2,\ldots,N+1$: שורה $i+1$ מתארת העדפת פרה $i$ בשלם $D_{i}$.

פלט

כתבו לפלט הסטנדרטי.

  • שורה 1: שלם, מספר הכרטיסים המזערי ש-Farmer John צריך לשנות לקיבוץ המתואר.

דוגמאות

קלט 1

7
2
1
1
1
2
2
1

פלט 1

2

הערה

שבע פרות; כולן מלבד שלוש מעדיפות כעת קבוצה $1$.

שנו את כרטיסי הפרה הראשונה והאחרונה.

קרדיט לבעיה: Ionescu Victor ו-Brian Dean, 2007

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.