시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 256 MB | 9 | 4 | 3 | 37.500% |
There are two white pieces and one black king on a chess board. Each of the white pieces is a rook, a bishop, or a queen. Currently, it is time for the the White player to move. You are playing for White, and you need to checkmate the black king as soon as possible. Write a program that will determine the minimum number of moves White needs to perform to checkmate the black king, assuming Black follows the best possible strategy for prolonging the game.
Some information about the chess rules:
a
' to 'h
', and the rows by the digits '1
' to '8
'.The first line of input contains the number of positions (which is at most $1.5 \cdot 10^5$), and each of the following lines contains a description of a single position. A position is represented by the locations of the three pieces on the board: the black king first and then the two white pieces. The position of each white piece is preceded with a type-specifying character: 'R
' means rook, 'B
' means bishop, and 'Q
' means queen. It is guaranteed that no two pieces occupy the same square and there is no check at the initial position. Other than that, the given position can be arbitrary: for example, both white pieces can be queens.
Output one line for each position in the input. The line should contain the minimum number of moves which White needs to make to guarantee the checkmate, starting from the corresponding position. In case it is not possible to reach the goal, output $0$ for that position.
2 c7 R f1 R g6 f5 B b3 R h3
2 0