Logo
(追記) (追記ここまで)

31064번 - Cowntact Tracing 2 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB82021617529.915%

문제

Farmer John has $N$ cows in a line (1ドル \leq N \leq 3\cdot 10^5$). Unfortunately, there is a sickness spreading throughout.

Initially, some cows start off infected. Every night, an infected cow spreads the sickness to the cows on their left and right (if they exist). Once a cow is infected, she stays infected.

After some amount of nights, Farmer John realizes that the issue has gotten out of control, so he tests his cows to determine who has the sickness. Find the minimum number of cows that could have started with the sickness.

입력

The first line contains $N,ドル the number of cows that Farmer John has.

The next line contains an $N$ character bitstring of only 1ドル$s and 0ドル$s where a 1ドル$ represents an infected cow and a 0ドル$ represents an uninfected cow after some number of nights.

출력

Output a single integer: the minimum number of cows that could have started with the sickness.

제한

예제 입력 1

5
11111

예제 출력 1

1

Suppose the middle cow was the only cow to start off infected. Then the cows would be infected in the following order:

0 nights: 00100 (the third cow is initially infected)
1 night: -> 01110 (the second and fourth cows are now infected)
2 nights: -> 11111 (the first and fifth cows are now infected)
3 nights: -> 11111 (all cows already were infected, so no additional cows are infected)
 -> ...

After two or more nights, the final state of the cows would look like the input. There are many other initial states and number of nights that could have produced the input state, such as:

0 nights: 10001
1 night: -> 11011
2 nights: -> 11111

or:

0 nights: 01001
1 night: -> 11111

or:

0 nights: 01000
1 night: -> 11100
2 nights: -> 11110
3 nights: -> 11111

All of these initial states contain at least one infected cow.

예제 입력 2

6
011101

예제 출력 2

4

The only initial state and number of nights that could have led to this final state is if no nights have passed and each of the four infected cows in the input started off with the sickness.

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2023 December Contest > Bronze 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /