SlimeXResidentSlime
SRM 506 · 2010-11-01 · by dolphinigle
Problem Statement
You are on a level that is represented by an RxC rectangular grid of cells given in
- '.' : an empty cell.
- '#' : a wall.
- '$' : an empty cell where you initially reside.
- '1'-'9' : a stationary undead slime whose regenerative power is equal to the digit representing it.
- You start at the cell denoted by '$'.
- At the beginning of each turn, you either wait or move to one of the four adjacent cells (those which share a side with your current location). You cannot move to a cell which contains a wall.
- Next, if there's a dead slime in your new location, it will get revived.
- Next, if your new location is occupied by an undead slime, that slime gets killed. The killed slime will remain in the cell.
- Next, each slime is revived if its regenerative power is equal to the number of turns ago it was last killed.
- Finally, if at this moment all undead slimes are killed, you win the level. Otherwise, the turn advances and the game continues.
Constraints
- field will contain between 1 and 50 elements, inclusive.
- Each element of field will contain between 1 and 50 characters, inclusive.
- All the elements of field will contain the same number of characters.
- Each character in field will be '.', '#', '$', or '1'-'9'.
- There will be exactly one '$' in field.
- There will be at least one digit (i.e., a slime) in field.
{
"#1$",
".2."}
Returns: 3
Go down, then go left (killing the slime denoted by '2'). Finally, go up (killing the slime denoted by '1') and since no slime gets revived during this turn, you win the level.
{
"$",
"1",
"1"}
Returns: -1
It's impossible to defeat this level. Each time you kill a slime, the other slime gets revived.
{
"$124"}
Returns: 5
Go right, kill the slime denoted by '1'. Go right, kill the slime denoted by '2'. (After this, the slime denoted by '1' gets revived). Go right, kill the slime denoted by '4'. Go left, (the slime denoted by '2' immediately revives), and kill the slime denoted by '2'. Go left, kill the slime denoted by '1', and win the level.
{
"..999..",
".99999.",
".99$..."}
Returns: -1
{
"..999..",
".9999..",
".99$..."}
Returns: 9
Submissions are judged against all 167 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SlimeXResidentSlime with a public method int exterminate(vector<string> field) · 167 test cases · 2 s / 256 MB per case