#P9082. Coin Transport Challenge
Coin Transport Challenge
Coin Transport Challenge
This problem is based on a weekend strategy game where the objective is to collect all coins from a grid-based map and transport them back to the base. The map is a $$n \times n$$ grid with rows numbered from 0 to $$n-1$$ (top to bottom) and columns numbered from 0 to $$n-1$$ (left to right). The cell at position $$(0,0)$$ is designated as your base, which starts with 200 coins. Every other cell contains either a certain number of coins or a number of stones.
There are two types of movable units:
- Farmer: Can only enter cells without stones and collects coins. At the end of a round, if a farmer is on a cell containing coins, he picks up 10 coins (or all coins if there are fewer than 10). The coins are stored in his backpack (with unlimited capacity) until he returns to the base, where they are deposited.
- Tank: Can move into any cell and is able to clear stones. At the end of a round, if a tank is on a cell containing stones, it removes 10 stones (or all stones if there are fewer than 10).
The game is turn-based. In each round, every unit may move once to an adjacent cell (sharing a common edge). Two units may not occupy the same cell simultaneously. All movements occur instantaneously.
You may also recruit additional units at the base using the following commands, at a cost of 100 coins each (the base must have at least 100 coins before recruitment):
R FARMER
: Recruit a Farmer.R TANK
: Recruit a Tank.
The commands available during the game are as follows:
Command | Effect |
---|---|
R FARMER |
Buy a Farmer unit; it appears immediately at the base. |
R TANK |
Buy a Tank unit; it appears immediately at the base. |
M r1 c1 r2 c2 |
Move a unit from cell $$(r_1, c_1)$$ to an adjacent cell $$(r_2, c_2)$$. |
= |
End the current round. |
=== |
End the game for the current map. |
Your task is, for each given map, to output a sequence of commands so that, when executed, all coins on the map are returned to the base (note that coins may be spent for recruiting units). In other words, at the end of the game, no cell (other than the base) should contain any coins, and no farmer’s backpack should contain any coins.
Furthermore, each set of test cases comes with an average rounds limitation: if there are $$T$$ maps and the limit is $$k$$ rounds on average, then your solution must finish each map within at most $$T \cdot k$$ rounds. (Here, for each map the number of rounds is defined as the number of times you issue the command =
plus 1.)
inputFormat
The input consists of one or more maps. For each map, the first line contains an integer $$n$$ representing the grid size. The next $$n^2 - 1$$ lines (or an appropriate format) describe the contents of each cell other than the base at $$(0,0)$$. Each cell contains either a positive integer (indicating the number of coins) or a positive integer prefixed by a sign (indicating the number of stones). An additional integer $$k$$ is provided that sets the average round limit for the set of maps.
outputFormat
Output a sequence of commands (each on a separate line) that adheres to the command formats below:
Command | Effect |
---|---|
R FARMER |
Recruit a Farmer at the base. |
R TANK |
Recruit a Tank at the base. |
M r1 c1 r2 c2 |
Move a unit from cell $$(r_1, c_1)$$ to an adjacent cell $$(r_2, c_2)$$. |
= |
End the current round. |
=== |
End the game for the current map. |
Your output must ensure that by the end of the game, every coin originally present on the map has been transported back to the base and no coins remain on any cell or in any Farmer’s backpack.
sample
1
200
===