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.