teddy online judge
teddy es un oso de peluche
Limite de tiempo : 1 seg. Total runs : 1 Aceptados : 0
Most console role-playing games, such as the famous Final Fantasy and Dragon Quest games, have towns filled with inconsequential characters that wander around aimlessly, waiting for the player to speak to them.
You"ve been tasked with the development of the town character (or NPC) movement handling for a new game.
Any given NPC has a movement script with a few simple commands:
|NORTH x||Move NORTH (up) x steps, one per turn|
|SOUTH x||Move south (down) x steps, one per turn|
|EAST x||Move east (right) x steps, one per turn|
|WEST x||Move west (left) x steps, one per turn|
|PAUSE x||Stay in the current location x turns|
Note that the individuals who write the NPC movement scripts aren"t the most careful coders in the world. Sometimes the scripts have the NPCs attempting to walk through walls and other barriers or even off the edge of the map. When this occurs, all of the steps of movement that would put the NPC in such an invalid location are converted into PAUSEs. For example, given this small snippet of a town:
...# .1.# ...#
if the NPC represented by the 1 had EAST 5 as their next command, that would be converted on the fly to EAST 1 followed by PAUSE 4. This processing must be done before determining whether a script is cyclic or reversible.
A script is cyclic if, at the end of the script, the NPC back in their starting position. This sort of script is simply looped indefinitely. The other type of script is reversible; if, at the end of the script, the NPC is not back in their starting position, they then run a reversed copy of the script, with directions switched (WEST becomes EAST, EAST becomes WEST, NORTH becomes SOUTH, and SOUTH becomes NORTH) and PAUSEs intact. The end result is the character returning to their starting location.
|Original script segment||Reversed script segment|
| SOUTH 1
| WEST 1
For the sake of this problem, you can assume that no NPCs will ever attempt to occupy the same location on the map at the same time, although one may enter a location on the same turn as a different NPC leaves it, which is valid behavior.
The simulation starts at turn 0; your task is to show, given a map and set of NPCs with their scripts, what the simulation looks like after a large number of turns have passed.
1 2 5 5 ...#. .1.#. ...#. ...2. ..... 1 4 EAST 5 SOUTH 1 PAUSE 1 WEST 1 2 4 EAST 1 SOUTH 1 WEST 1 NORTH 1 22
DATA SET #1 ...#. ...#. ..1#. ..... ....2