codeforces-scrape

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

719B.md (1774B)


      1 Source: https://codeforces.com/problemset/problem/719/B
      2 
      3 B. Anatoly and Cockroaches
      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 Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
     22 
     23 Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
     24 
     25 Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
     26 
     27 Input
     28 
     29 The first line of the input contains a single integer *n* (1 ≤ *n* ≤ 100 000) — the number of cockroaches.
     30 
     31 The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
     32 
     33 Output
     34 
     35 Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 5  
     43 rbbrr
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 1
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 5  
     56 bbbbb
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 2
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 3  
     69 rbr
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 0
     76 ```
     77 
     78 Note
     79 
     80 In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
     81 
     82 In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
     83 
     84 In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.