#CCBCHHAI0000030. Dừng khi ba lần đúng liên tiếp (Three Consecutive Successes)
Dừng khi ba lần đúng liên tiếp (Three Consecutive Successes)
Three Consecutive Successes
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Read a stream of 0/1 results. One denotes success; zero denotes failure and resets the current run of successes. Stop at the first occurrence of three consecutive ones, and print the number of results read.
Input
A sequence of zeros and ones with at least one run of three consecutive ones. The final integer completes the first such run; nothing follows.
Output
Print the number of reads including the third 1 completing the first run.
Subtasks
- Subtask 1 (20%): At most values.
- Subtask 2 (30%): At most values.
- Subtask 3 (50%): At most values.
Examples
Example 1
Input
1 1 0 1 1 1
Output
6
Explanation
Initial ones form a run of length two, then zero resets it. The final three ones complete at read six.
Example 2
Input
1 1 1
Output
3
Explanation
The first three results are ones; the first triple completes at read three.