#P1917. Winning Strategy in Three-in-a-Row
Winning Strategy in Three-in-a-Row
Winning Strategy in Three-in-a-Row
In this problem, two players, small a and uim, play a variant of Tic Tac Toe (also known as three‐in‐a‐row) on a 3×3 board. In this game, a player wins if he or she manages to form a line (horizontal, vertical, or diagonal) of 3 consecutive pieces. The game state is given by a board that contains less than 3 pieces. Moreover, if small a has played, his first move is always placed in the center cell. We assume that small a uses the symbol X and uim uses the symbol O.
The task is to determine, given the current board, whether small a has a forced win strategy (i.e. a strategy that guarantees a win regardless of how uim plays, provided that small a plays optimally). All formulas are given in LaTeX format. For example, a win is achieved if a player has a line of $3$ consecutive symbols.
inputFormat
The input consists of 3 lines, each containing a string of exactly 3 characters. Each character is either 'X', 'O', or '.', where '.' denotes an empty cell. The board represents a 3×3 grid (the "nine palace grid"). Note that if small a has played, his first move is always at the center (i.e. cell (1,1) if we index rows and columns from 0). The board will have fewer than 3 pieces in total.
outputFormat
Output 1 if small a (playing as X) has a forced win strategy assuming both players play optimally; otherwise output 0.
sample
...
.X.
...
0