7897: Tic Tac Toe

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

The game of Tic Tac Toe is played on an

n

-by-

n

grid (where

n

is usually but not necessarily three). Two players alternate placing symbols on squares of the grid. One player places Xes and the other player places Os. The player placing Xes always goes first. When the grid contains a vertical, horizontal, or diagonal sequence of at least

m

consecutive squares all containing the same symbol, the game ends and the winner is the player who placed the last symbol. When all the squares of the grid are filled, if neither player has won, the game ends in a draw.

Your task is to analyze the state of a Tic Tac Toe board, and determine whether the game is still in progress, or if it has completed, who won, or if the game ended in a draw. You should also detect erroneous states of the Tic Tac Toe board that could never occur during an actual game.

输入

The first line of input contains the two integers n and m, separated by spaces, with 1 <= m <= n <= 2000. The following n lines of input each contain one row of the Tic Tac Toe board. Each of these lines contains exactly n characters, and each of these characters is either anX, anO, or a period (.), indicating an empty square.

输出

Output a single line containing the appropriate stringX WINS,O WINS, orDRAWif the game is over, the stringIN PROGRESSif the game has not yet finished, orERRORif the state of the board could never occur during a game.

样例输入 复制

3 3
..X
OOX
..X

样例输出 复制

X WINS

来源/分类