codeforces-scrape

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

436B.md (3905B)


      1 Source: https://codeforces.com/problemset/problem/436/B
      2 
      3 B. Om Nom and Spiders
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
     22 
     23  ![](https://espresso.codeforces.com/c688e7bdfac565e6eb537218d7d2dc9263f4b572.png) 
     24 
     25 The park can be represented as a rectangular *n* × *m* field. The park has *k* spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.
     26 
     27 Om Nom isn't yet sure where to start his walk from but he definitely wants:
     28 
     29 * to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders);
     30 * to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park).
     31 
     32 We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.
     33 
     34 Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell.
     35 
     36 Input
     37 
     38 The first line contains three integers *n*, *m*, *k* (2 ≤ *n*, *m* ≤ 2000; 0 ≤ *k* ≤ *m*(*n* - 1)).
     39 
     40 Each of the next *n* lines contains *m* characters — the description of the park. The characters in the *i*-th line describe the *i*-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down).
     41 
     42 It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly *k* spiders.
     43 
     44 Output
     45 
     46 Print *m* integers: the *j*-th integer must show the number of spiders Om Nom will see if he starts his walk from the *j*-th cell of the first row. The cells in any row of the field are numbered from left to right.
     47 
     48 Examples
     49 
     50 Input
     51 
     52 ```
     53 3 3 4  
     54 ...  
     55 R.L  
     56 R.U
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 0 2 2
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 2 2 2  
     69 ..  
     70 RL
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 1 1
     77 ```
     78 
     79 Input
     80 
     81 ```
     82 2 2 2  
     83 ..  
     84 LR
     85 ```
     86 
     87 Output
     88 
     89 ```
     90 0 0
     91 ```
     92 
     93 Input
     94 
     95 ```
     96 3 4 8  
     97 ....  
     98 RRLL  
     99 UUUU
    100 ```
    101 
    102 Output
    103 
    104 ```
    105 1 3 3 1
    106 ```
    107 
    108 Input
    109 
    110 ```
    111 2 2 2  
    112 ..  
    113 UU
    114 ```
    115 
    116 Output
    117 
    118 ```
    119 0 0
    120 ```
    121 
    122 Note
    123 
    124 Consider the first sample. The notes below show how the spider arrangement changes on the field over time:
    125 
    126 ```
    127 ...        ...        ..U       ...  
    128 R.L   ->   .*U   ->   L.R   ->  ...  
    129 R.U        .R.        ..R       ...
    130 ```
    131 
    132 Character "*" represents a cell that contains two spiders at the same time.
    133 
    134 * If Om Nom starts from the first cell of the first row, he won't see any spiders.
    135 * If he starts from the second cell, he will see two spiders at time 1.
    136 * If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2.