TurtleGame
SRM 726 · 2017-12-18 · by subscriber
Problem Statement
Constraints
- board will contain between 2 and 20 elements, inclusive.
- All elements in board will contain the same sumber of characters.
- Each element in board will contain between 2 and 20 characters, inclusive.
- Each character in board will be either '.' or '#'.
- It is guaranteed that there is at least one undestroyed turtle path.
{"..",
".."}
Returns: "Win"
This board contains two different turtle paths. Hero has two moves that don't lose him the game: he can remove either the top right or the bottom left cell. Each of these moves will leave only one of the two turtle paths, and Jack will have no valid moves left. Jack's move will create a board that is not turtle-friendly, which means that Hero will win the game.
{"...",
".#.",
".#.",
"..."}
Returns: "Lose"
Again there are only two turtle paths. However, now they are longer. Regardless of which cell Hero removes (other than the top left and the bottom right cell), his move will create three cells that can be destroyed "for free". Since 3 is an odd number, Jack will be the one to remove the last of these three cells. In the following turn Hero will lose the game.
{".##",
"..#",
"#.."}
Returns: "Lose"
{"....",
"...#",
"#...",
"...."}
Returns: "Win"
{"...#.",
"....#",
"#....",
"..##."}
Returns: "Win"
Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TurtleGame with a public method string getwinner(vector<string> board) · 62 test cases · 2 s / 256 MB per case