codeforces-scrape

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

1535C.md (1338B)


      1 Source: https://codeforces.com/problemset/problem/1535/C
      2 
      3 C. Unstable String
      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 You are given a string $s$ consisting of the characters 0, 1, and ?.
     22 
     23 Let's call a string unstable if it consists of the characters 0 and 1 and any two adjacent characters are different (i. e. it has the form 010101... or 101010...).
     24 
     25 Let's call a string beautiful if it consists of the characters 0, 1, and ?, and you can replace the characters ? to 0 or 1 (for each character, the choice is independent), so that the string becomes unstable.
     26 
     27 For example, the strings 0??10, 0, and ??? are beautiful, and the strings 00 and ?1??1 are not.
     28 
     29 Calculate the number of beautiful contiguous substrings of the string $s$.
     30 
     31 Input
     32 
     33 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — number of test cases.
     34 
     35 The first and only line of each test case contains the string $s$ ($1 \le |s| \le 2 \cdot 10^5$) consisting of characters 0, 1, and ?.
     36 
     37 It is guaranteed that the sum of the string lengths over all test cases does not exceed $2 \cdot 10^5$.
     38 
     39 Output
     40 
     41 For each test case, output a single integer — the number of beautiful substrings of the string $s$.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 3
     49 0?10
     50 ???
     51 ?10??1100
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 8
     58 6
     59 25
     60 ```