XorGame
TCO12 Championship Round · 2012-03-27 · by wrong
Problem Statement
You are given two
When the string turns into E, player A wins. If player A can win the game, return the minimum possible number of turns A has to take. (We assume that if player A can ensure a win, then player B uses a strategy that postpones his loss for as long as possible.) If player A cannot win the game, return -1 instead.
Constraints
- S will contain between 1 and 50 characters, inclusive.
- S and E will contain the same number of characters.
- Each character in S and E will be '0' or '1'.
"10101" "11011" Returns: 1
Player A can win in the first turn by flipping characters 1 through 3 (0-based indices).
"001100" "001100" Returns: 0
Player A wins immediately after the game begins.
"110" "011" Returns: 2
In this case, player A cannot win in her first turn. However, she can start by flipping characters 1 and 2, producing the string "101". Regardless of what player B does (and even if he chooses not to flip anything), she will then have winning move in her second turn.
"10101010" "11111111" Returns: -1
"001011010101101" "001000101101101" Returns: 1
Submissions are judged against all 94 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class XorGame with a public method int play(string S, string E) · 94 test cases · 2 s / 256 MB per case