BoardEscape
SRM 676 · 2015-11-03 · by lg5293
Problem Statement
Alice and Bob have a rectangular board divided into a grid with r rows and c columns.
The grid is described by the
- 'E' denotes an exit. There may be arbitrarily many exits, possibly zero.
- 'T' means the square contains a single token. There may be arbitrarily many tokens, possibly zero.
- '#' denotes an obstacle.
- '.' denotes an empty cell.
Alice and Bob will play a game on this board.
The game is parameterized by the
- The player chooses a single token on the board and moves it one square up, down, left, or right. The token cannot go over the edge of the board and it cannot enter a cell with an obstacle. The token may be moved into a cell that already contains other token(s). During the game, arbitrarily many tokens may share the same cell.
- If this token is on an exit, it disappears from the board.
- Otherwise, subtract one from the number on the token. If the number on the token is zero, remove it from the board. (The numbers on other tokens do not change.)
The first player unable to make a move loses the game.
You are given the
Constraints
- r,c will be between 1 and 50, inclusive.
- s will contain exactly r elements, each consisting of c characters.
- Each character of each element of s will be one of 'T', 'E', '#', or '.'.
- k will be between 1 and 1,000,000,000, inclusive.
{"TE"}
2
Returns: "Alice"
Alice can move the token directly to the exit on her first move, making Bob unable to move.
{"E#E",
"#T#",
"E#E"}
1000000
Returns: "Bob"
Alice is unable to make the first move in this case.
{"T.T.T.",
".E.E.E"}
1
Returns: "Alice"
{"TTE"}
6
Returns: "Alice"
{"..........................",
"......TTT..TTT..T...T.....",
".....T.....T..T.TT.TT.....",
"......TTT..TTT..T.T.T.....",
".........T.T.T..T...T.....",
"......TTT..T..T.T...T.....",
"..........................",
"...E#E#E#E#E#E#E#E#E#E#...",
"..........................",
"......TTT..TTT...TTT......",
".....T........T.T.........",
"......TTT.....T..TTT......",
".....T...T...T..T...T.....",
"......TTT....T...TTT......",
"..........................",
"...#E#E#E#E#E#E#E#E#E#E...",
"..........................",
"....TT...T...T..T.TTT.T...",
"...T.....T...T..T.T...T...",
"...T.TT..T...TTTT.TT..T...",
"...T..T..T...T..T.T.......",
"....TT...TTT.T..T.T...T...",
".........................."}
987654321
Returns: "Bob"
Submissions are judged against all 110 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BoardEscape with a public method string findWinner(vector<string> s, int k) · 110 test cases · 2 s / 256 MB per case