#P4576. [CQOI2013] 棋盘游戏

[CQOI2013] 棋盘游戏

Description

On an n×nn \times n (n2n \ge 2) board, there is one white piece and one black piece. Players A and B move alternately, with A moving first.

  • A’s move rule: A can only move the white piece. It can move exactly one square in one of the four orthogonal directions (up, down, left, right).
  • B’s move rule: B can only move the black piece. It can move either one or two squares in one of the four orthogonal directions (up, down, left, right).

As in the usual “capture” rule, when a player moves their piece onto the square occupied by the opponent’s piece, they win.

Both players are smart: when a win is possible, they will win as soon as possible; when they can only lose, they will delay as much as possible. Your task is to determine who will win and in how many moves.

For example, when n=2n=2, the white piece is at (1,1)(1,1) and the black piece is at (2,2)(2,2). Although A has two legal moves, B can always win on the second move.

Input Format

A single line containing five integers nn, r1r_1, c1c_1, r2r_2, c2c_2, representing the board size and the positions of the pieces.

The white piece is at (r1,c1)(r_1,c_1), and the black piece is at (r2,c2)(r_2,c_2) (1r1,c1,r2,c2n)(1 \le r_1,c_1,r_2,c_2 \le n). The positions of the white and black pieces are guaranteed to be different.

Output Format

Output a single line: the game result.

If A wins, output WHITE x.

If B wins, output BLACK x.

If neither player has a forced win, output DRAW.

Here xx is the number of moves.

2 1 1 2 2
BLACK 2

Hint

For 100% of the testdata, n20n \le 20.

Translated by ChatGPT 5