Battle simulation
Time limit2sMemory limit1024 MB
Simulate dash commands on a grid where units stop when they meet an enemy and cannot exceed their movement power, then print final positions.
- Level
Medium6 of 10
- Topics
- Shortest path, Simulation, Graph
- Solved
- No attempts yet
Problem
You are building a battle simulation game where two factions fight on a 2D grid map of size . Each cell can be written as a coordinate pair . Cells in the first row are from left to right, and cells in the second row are . Every cell up to the last row is written in the same way. The cells directly above, below, left, and right of a cell are called adjacent to that cell.
Problem
The map is made of various terrains, and each terrain has a fixed roughness value. Several units are placed on the map without overlapping, and each unit belongs to one of the two factions. As long as it stays on the map, a unit can move up, down, left, or right to an adjacent cell. Each move costs stamina equal to the roughness of the cell entered. Some terrains are too rough to enter at all. Two units from different factions that are adjacent to each other are in combat.
Problem
All units ate a hearty combat ration before heading out, so their stamina is unlimited. However, each unit has a limit on the total stamina it can spend in a single dash, and this limit is called the unit's movement power. A dash is a tactical move in which a unit in combat rushes to a nearby target cell in one go, passing through one or more cells. A dash is possible only if no other unit is on the target cell. While dashing, a unit may pass through allied units. If it meets a unit of the opposing faction and becomes adjacent to it, combat starts and the unit must stop there. However, if the selected unit was already in combat, it can dash out of combat.
Problem
A bot picks random units and issues dash commands to test the game for bugs. The bot sometimes issues dash commands that cannot be carried out. A command is impossible if the target cell holds another unit, if the target cell is impassable terrain, or if no path to the target exists within the unit's movement power. If the game has no bugs, these commands must be ignored.
Problem
Now it is time to check for bugs. Given the bot's commands in time order, write a program that prints each unit's coordinates after all commands are processed in order.
Input
The first line has three space-separated integers , , and , the number of terrain types, the map height, and the map width. (, )
The next lines each contain integers giving the terrain number of each cell from left to right. Each number is between and , inclusive.
The next line contains integers (, ). If is , terrain is too rough to enter. Otherwise, is the roughness of terrain .
The next line contains the number of units . ()
The next lines describe units 1 through in order. Each line has four integers , , , : the movement power, the faction, and the and coordinates of the unit's cell. (, , , )
Each cell holds at most one unit, and no unit is placed on a cell whose terrain cannot be entered.
The next line contains the number of dash commands . ()
The next lines each contain three integers , , , meaning that unit dashes to . (, , )
Output
Print lines. After all dash commands are processed, line contains the coordinates and of unit , separated by a space.
Hint
The first dash cannot be carried out. Ignoring combat, a unit could reach and then along . However, the enemy unit at starts combat at , so cannot be reached. No detour avoids combat either, so the command is ignored.
The second dash targets a cell with impassable terrain, so it is ignored.
The third dash is possible. The path costs stamina, which does not exceed the unit's movement power.
After all commands, unit 1 is at because of the last command, and unit 2 stays at its initial position.