codeforces-scrape

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

1025C.md (1821B)


      1 Source: https://codeforces.com/problemset/problem/1025/C
      2 
      3 C. Plasticine zebra
      4 
      5 time limit per test
      6 
      7 1 second
      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 Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
     22 
     23 Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
     24 
     25 Before assembling the zebra Grisha can make the following operation $0$ or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
     26 
     27 Determine the maximum possible length of the zebra that Grisha can produce.
     28 
     29 Input
     30 
     31 The only line contains a string $s$ ($1 \le |s| \le 10^5$, where $|s|$ denotes the length of the string $s$) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
     32 
     33 Output
     34 
     35 Print a single integer — the maximum possible zebra length.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 bwwwbwwbw
     43 ```
     44 
     45 Output
     46 
     47 ```
     48 5
     49 ```
     50 
     51 Input
     52 
     53 ```
     54 bwwbwwb
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 3
     61 ```
     62 
     63 Note
     64 
     65 In the first example one of the possible sequence of operations is bwwwbww|bw $\to$ w|wbwwwbwb $\to$ wbwbwwwbw, that gives the answer equal to $5$.
     66 
     67 In the second example no operation can increase the answer.