TORNJEVI - TORNJEVI
We are being attacked on a map represented by a rectangular grid of R×S squares. The attackers are barefoot robbers, and we use small cannons on small wooden towers to defend ourselves.
Each tower is equipped with two cannons, placed to fire in a 90 degree angle. More precisely, cannons on one tower can be set to fire in one of the following four configurations:
- fire left and down;
- fire down and right;
- fire right and up;
- fire up and left.
A cannon ball that hits the attacker destroys him and continues to fly in the same direction. A cannon ball which hits a castle stops and does no damage to the castle (because castles are big and strong). But, when a cannon ball hits a tower, it destroys it (because towers are small and fragile).
We want to turn the cannons on the towers so that, when we fire exactly one shot from every cannon, we destroy all the attackers, and all our towers remain undamaged.
Input
The first line contains two integers R and S (1 ≤ R, S ≤ 100), the dimensions of the map.
The next R lines contain S characters each, the map.
Each character on the map can be the uppercase letter 'T' (tower), lowercase letter 'n' (attacker), the character '#' (castle) or the character '.' (empty).
Note: There will always be a solution, although not necessarily unique.
Output
Output the map in the same format as in the input, replacing 'T' characters with the orientations of the cannons – each tower should be replaced with one of the digits '1', '2', '3' or '4', corresponding to the four orientations as described above.
Examples
Input: 9 13 ............. ...........n. .n.T..nnnn#.. ............. .T#n..n....T. ............. .n.T..T....n. ............. ......n...... Output: ............. ...........n. .n.3..nnnn#.. ............. .4#n..n....4. ............. .n.1..2....n. ............. ......n...... |
Input: 5 9 .n..T..n. .T..n.... .n..#..n. ....n..T. .n..T..n. Output: .n..4..n. .2..n.... .n..#..n. ....n..4. .n..3..n. |
Input: 9 8 n.Tnnnnn nnnnnnTn nTnnnnnn nnnnTnnn Tnnnnnnn ..#nnTnn nnnnnnnT nnnTn.n. .nTnnnnn Output: n.3nnnnn nnnnnn1n n2nnnnnn nnnn1nnn 3nnnnnnn ..#nn4nn nnnnnnn4 nnn4n.n. .n3nnnnn |
hide comments
karlo_2107:
2022-12-31 18:46:00
if u want to kill yourself, this is definetlly the best way!
|
|
kaneki_kun:
2020-08-27 22:13:08
AC in the fourth trial :(
|
Added by: | Bin Jin |
Date: | 2011-07-16 |
Time limit: | 0.200s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | CROATIAN HIGHSCHOOL COMPETITIONS IN INFORMATICS 2007, Final Exam #2 |