codeforces-scrape

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

405B.md (2530B)


      1 Source: https://codeforces.com/problemset/problem/405/B
      2 
      3 B. Domino Effect
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
     22 
     23 Chris arranges *n* dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
     24 
     25 After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
     26 
     27  ![](https://espresso.codeforces.com/4d23cce3d282d9b423152c1399debe243751c2c3.png) 
     28 
     29 Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
     30 
     31 Input
     32 
     33 The first line contains a single integer *n* (1 ≤ *n* ≤ 3000), the number of the dominoes in the line. The next line contains a character string *s* of length *n*. The *i*-th character of the string *s**i* is equal to
     34 
     35 * "L", if the *i*-th domino has been pushed to the left;
     36 * "R", if the *i*-th domino has been pushed to the right;
     37 * ".", if the *i*-th domino has not been pushed.
     38 
     39 It is guaranteed that if *s**i* = *s**j* = "L" and *i* < *j*, then there exists such *k* that *i* < *k* < *j* and *s**k* = "R"; if *s**i* = *s**j* = "R" and *i* < *j*, then there exists such *k* that *i* < *k* < *j* and *s**k* = "L".
     40 
     41 Output
     42 
     43 Output a single integer, the number of the dominoes that remain vertical at the end of the process.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 14  
     51 .L.R...LR..L..
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 4
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 5  
     64 R....
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 0
     71 ```
     72 
     73 Input
     74 
     75 ```
     76 1  
     77 .
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 1
     84 ```
     85 
     86 Note
     87 
     88 The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
     89 
     90 In the second example case, all pieces fall down since the first piece topples all the other pieces.
     91 
     92 In the last example case, a single piece has not been pushed in either direction.