codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1553C.md (3352B)


      1 Source: https://codeforces.com/problemset/problem/1553/C
      2 
      3 C. Penalty
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Consider a simplified penalty phase at the end of a football match.
     22 
     23 A penalty phase consists of at most $10$ kicks, the first team takes the first kick, the second team takes the second kick, then the first team takes the third kick, and so on. The team that scores more goals wins; if both teams score the same number of goals, the game results in a tie (note that it goes against the usual football rules). The penalty phase is stopped if one team has scored more goals than the other team could reach with all of its remaining kicks. For example, if after the $7$-th kick the first team has scored $1$ goal, and the second team has scored $3$ goals, the penalty phase ends — the first team cannot reach $3$ goals.
     24 
     25 You know which player will be taking each kick, so you have your predictions for each of the $10$ kicks. These predictions are represented by a string $s$ consisting of $10$ characters. Each character can either be 1, 0, or ?. This string represents your predictions in the following way:
     26 
     27 * if $s_i$ is 1, then the $i$-th kick will definitely score a goal;
     28 * if $s_i$ is 0, then the $i$-th kick definitely won't score a goal;
     29 * if $s_i$ is ?, then the $i$-th kick could go either way.
     30 
     31 Based on your predictions, you have to calculate the minimum possible number of kicks there can be in the penalty phase (that means, the earliest moment when the penalty phase is stopped, considering all possible ways it could go). Note that the referee doesn't take into account any predictions when deciding to stop the penalty phase — you may know that some kick will/won't be scored, but the referee doesn't.
     32 
     33 Input
     34 
     35 The first line contains one integer $t$ ($1 \le t \le 1\,000$) — the number of test cases.
     36 
     37 Each test case is represented by one line containing the string $s$, consisting of exactly $10$ characters. Each character is either 1, 0, or ?.
     38 
     39 Output
     40 
     41 For each test case, print one integer — the minimum possible number of kicks in the penalty phase.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 4
     49 1?0???1001
     50 1111111111
     51 ??????????
     52 0100000000
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 7
     59 10
     60 6
     61 9
     62 ```
     63 
     64 Note
     65 
     66 Consider the example test:
     67 
     68 In the first test case, consider the situation when the $1$-st, $5$-th and $7$-th kicks score goals, and kicks $2$, $3$, $4$ and $6$ are unsuccessful. Then the current number of goals for the first team is $3$, for the second team is $0$, and the referee sees that the second team can score at most $2$ goals in the remaining kicks. So the penalty phase can be stopped after the $7$-th kick.
     69 
     70 In the second test case, the penalty phase won't be stopped until all $10$ kicks are finished.
     71 
     72 In the third test case, if the first team doesn't score any of its three first kicks and the second team scores all of its three first kicks, then after the $6$-th kick, the first team has scored $0$ goals and the second team has scored $3$ goals, and the referee sees that the first team can score at most $2$ goals in the remaining kicks. So, the penalty phase can be stopped after the $6$-th kick.
     73 
     74 In the fourth test case, even though you can predict the whole penalty phase, the referee understands that the phase should be ended only after the $9$-th kick.