#P4621. [COCI 2012/2013 #6] BAKTERIJE
[COCI 2012/2013 #6] BAKTERIJE
Description
There is a rectangular area with rows and columns. Rows are numbered from to from top to bottom, and columns are numbered from to from left to right. There are bacteria placed in these cells. Each bacterium has its own direction and movement rules.
The rules are as follows: it reads the digit in its current cell, then turns clockwise by exactly times. If it is facing the boundary of the rectangle, it turns . Finally, it moves into the cell it is facing.
We place a trap in one cell. When all bacteria enter the trap at the same time, the trap is activated, and the bacteria will be destroyed within one second.
Given all information, determine when all bacteria are destroyed.
Input Format
The first line contains three positive integers .
The next line contains two integers , meaning there is a trap at row , column .
Then each bacterium is described in order:
- First, one line contains two integers and one letter , representing its row and column coordinates and its direction.
Umeans up,Dmeans down,Lmeans left, andRmeans right. - Next is a matrix giving the value for this bacterium in every cell, with .
Output Format
Output one integer on one line: the last time when the bacteria are killed. If it is impossible to destroy all of them, output .
3 3 1
2 2
1 1 R
010
000
000
3
3 4 2
2 2
3 4 R
2327
6009
2112
3 2 R
1310
2101
1301
8
4 4 3
4 3
1 1 U
1001
0240
3322
2327
1 3 L
9521
2390
3020
2421
2 2 D
3397
2013
1102
7302
296
Hint
Constraints: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号