Connect3
Time limit0.5sMemory limit512 MB
Given Black's opening column x and White's winning square (a,b), count final 4x4 board states where White's move there completes three in a row first.
- Level
Medium5 of 10
- Topics
- Backtracking, Simulation, Implementation
- Solved
- No attempts yet
Problem
Connect3 is a simplified version of Connect4. Two players, black and white, take turns putting stones of their own color on a board. Each square is written as , where is the row and is the column. The lower left square is and the upper right square is .
On a turn a player chooses a column, and the stone falls to the lowest empty square of that column. Square can be taken only after and are occupied.
The board of Connect3. Each square is written as with row and column .
The game ends the moment three stones of the same color stand next to each other in a row, in a column, or on a diagonal, and the player of that color wins. While no such triple exists, play goes on.
Black moves first and puts a stone on square . After that white and black alternate. The game ends when white puts a stone on square , so the white stone on is the one that completes three white stones in a line. Let be the board at that moment. Count how many different boards are possible. The order in which the stones were placed does not matter, so two boards are the same only when every square holds the same thing, a black stone, a white stone, or nothing. If no game can end this way, the answer is 0.
Input
The first line has one integer (), the column of the first stone, which black puts on square .
The second line has two integers and (, ), the square where the last stone of the game is put.
Output
Print one integer, the number of different final boards .