CF Zepto Code Rush 2014 B. Om Nom and Spiders

Source: Internet
Author: User
Tags time 0

Om Nom and Spiderstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

The park can be represented as a rectangularNLimit × limitMField. The park hasKSpiders, 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 ctions (left, right, down, up ). in a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding ction. if there is no cell in the given ction, 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.

Om Nom isn't yet sure where to start his walk from but he definitely wants:

  • 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 );
  • To walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park ).

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.

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.

Input

The first line contains three integersN, Bytes,M, Bytes,K(2 cores ≤ CoresN, Bytes,MMemory ≤ memory 2000; 0 memory ≤ memoryKLimit ≤ limitM(NUpload-Progress 1 )).

Each of the nextNLines containsMCharacters-the description of the park. The characters inI-Th line describeI-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 ).

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 exactlyKSpiders.

Output

PrintMIntegers:J-Th integer must show the number of spiders Om Nom will see if he starts his walk fromJ-Th cell of the first row. The cells in any row of the field are numbered from left to right.

Sample test (s) Input
3 3 4...R.LR.U
Output
0 2 2 
Input
2 2 2..RL
Output
1 1 
Input
2 2 2..LR
Output
0 0 
Input
3 4 8....RRLLUUUU
Output
1 3 3 1 
Input
2 2 2..UU
Output
0 0 
Note

Consider the first sample. The notes below show how the spider arrangement changes on the field over time:

...        ...        ..U       ...R.L   ->   .*U   ->   L.R   ->  ...R.U        .R.        ..R       ...

Character "*" represents a cell that contains two spiders at the same time.

  • If Om Nom starts from the first cell of the first row, he won't see any spiders.
  • If he starts from the second cell, he will see two spiders at time 1.
  • If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2.


Water problems, fraud on the second.


The AC code is as follows:


# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # define M 100005 # define ll long longusing namespace std; char a [2005] [2005]; int main () {int n, m, k; int I, j; int B [2005]; memset (B, 0, sizeof B); scanf ("% d", & n, & m, & k); for (I = 0; I <n; I ++) scanf ("% s", a [I]); for (I = 1; I <n; I ++) for (j = 0; j <m; j ++) {if (a [I] [j] = 'R' & I + j <m) // I + j <m dispensable, however, he commented on my WA and added B [I + j] ++; if (a [I] [j] = 'l' & j-I> = 0) B [j-I] ++; if (a [I] [j] = 'U') {if (I % 2 = 0) B [j] ++ ;}} for (I = 0; I <m; I ++) printf ("% d", B [I]); printf ("\ n"); return 0 ;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.