#P3192. [HNOI2007] 胜负一子

[HNOI2007] 胜负一子

Description

Gomoku is a widely played board game. On a 15×1515\times 15 board, two players play with black and white stones (similar to Go). Black moves first. Once a stone is placed, it cannot be lifted; that is, there are no moving or capturing moves.

To simplify the problem, assume there are no “forbidden moves” for Black. “Forbidden moves” is a Gomoku term referring to places where a move is not allowed. When a player first forms a connected line of 55 stones in one of the horizontal, vertical, 4545-degree diagonal, or 135135-degree diagonal directions, that player wins.

Consider an endgame position with Black to move. Please output the minimum number of moves for Black to win and all distinct next moves that allow Black to win in that number of moves.

Input Format

There are 1515 lines, each containing 1515 integers separated by a space. Let the integer in the ii-th row and the jj-th column be vi,jv_{i,j}. Use vi,j=0,1,2v_{i,j}=0,1,2 to indicate that the position at row ii, column jj is empty, has a black stone, or has a white stone, respectively. Input is given from the top-left corner, in left-to-right and top-to-bottom order. That is, the first integer v1,1v_{1,1} represents the state of row 11, column 11, and the last integer v15,15v_{15,15} represents the state of row 1515, column 1515.

Output Format

The first line contains two integers aa and bb, where aa is the minimum number of moves for Black to win, and bb is the number of distinct next moves by which Black can win in aa moves.

From the second line to the (b+1)(b+1)-th line, each line contains two integers that represent a row ii and a column jj for one such next move by Black that leads to a win in aa moves. These moves must be sorted in ascending order by 15×i+j15\times i+j.

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 2 0 2 0 0 0 0 0
0 0 0 0 0 0 2 1 1 2 0 0 0 0 0
0 0 0 0 0 0 0 1 2 1 0 0 0 0 0
0 0 0 0 0 0 2 1 1 1 1 2 0 0 0
0 0 0 0 0 0 0 1 0 1 0 1 0 0 0
0 0 0 0 0 0 2 2 0 1 1 0 2 0 0
0 0 0 0 0 0 0 0 0 2 0 2 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2
10 9
10 11

Hint

Translated by ChatGPT 5