codeforces-scrape

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

1675C.md (2499B)


      1 Source: https://codeforces.com/problemset/problem/1675/C
      2 
      3 C. Detective Task
      4 
      5 time limit per test
      6 
      7 2 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 Polycarp bought a new expensive painting and decided to show it to his $n$ friends. He hung it in his room. $n$ of his friends entered and exited there one by one. At one moment there was no more than one person in the room. In other words, the first friend entered and left first, then the second, and so on.
     22 
     23 It is known that at the beginning (before visiting friends) a picture hung in the room. At the end (after the $n$-th friend) it turned out that it disappeared. At what exact moment it disappeared — there is no information.
     24 
     25 Polycarp asked his friends one by one. He asked each one if there was a picture when he entered the room. Each friend answered one of three:
     26 
     27 * no (response encoded with 0);
     28 * yes (response encoded as 1);
     29 * can't remember (response is encoded with ?).
     30 
     31 Everyone except the thief either doesn't remember or told the truth. The thief can say anything (any of the three options).
     32 
     33 Polycarp cannot understand who the thief is. He asks you to find out the number of those who can be considered a thief according to the answers.
     34 
     35 Input
     36 
     37 The first number $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
     38 
     39 The following is a description of test cases.
     40 
     41 The first line of each test case contains one string $s$ (length does not exceed $2 \cdot 10^5$) — a description of the friends' answers, where $s_i$ indicates the answer of the $i$-th friend. Each character in the string is either 0 or 1 or ?.
     42 
     43 The given regularity is described in the actual situation. In particular, on the basis of answers, at least one friend can be suspected of stealing a painting.
     44 
     45 It is guaranteed that the sum of string lengths over the entire input data set does not exceed $2 \cdot 10^5$.
     46 
     47 Output
     48 
     49 Output one positive (strictly more zero) number – the number of people who could steal the picture based on the data shown.
     50 
     51 Example
     52 
     53 Input
     54 
     55 ```
     56 8
     57 
     58 0
     59 
     60 1
     61 
     62 1110000
     63 
     64 ?????
     65 
     66 1?1??0?0
     67 
     68 0?0???
     69 
     70 ??11
     71 
     72 ??0??
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 1
     79 1
     80 2
     81 5
     82 4
     83 1
     84 1
     85 3
     86 ```
     87 
     88 Note
     89 
     90 In the first case, the answer is $1$ since we had exactly $1$ friend.
     91 
     92 The second case is similar to the first.
     93 
     94 In the third case, the suspects are the third and fourth friends (we count from one). It can be shown that no one else could be the thief.
     95 
     96 In the fourth case, we know absolutely nothing, so we suspect everyone.