eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Game of Tiles

Game of Tiles

The Game of Tiles is a game for two players played over a rectangular board in the form of a table of \textbf{R} rows and \textbf{C }columns of square cells called tiles. At the beginning of the game, some of the tiles may be painted black and the rest remain white. Then, Player 1 and Player 2 alternate turns making a move and the first one that cannot make a valid move loses the game. The first move of the game is done by Player 1 and consists of choosing a white tile and writing the number 1 on it. After that, each subsequent move i consists of writing number i on an unused white tile that is adjacent horizontally or vertically (but not diagonally) to the tile numbered \textbf{i-1} Note that Player 1 always writes odd numbers and Player 2 always writes even numbers. The following figure shows three examples of possible configurations of a board with \textbf{R = 3} and \textbf{C = 4} during a game. On the left it shows the initial configuration. On the center it shows an intermediate state, where cells in gray mark the possible moves for Player 2. And on the right it shows the configuration when the game is won by Player 2, who chose the appropriate move. \includegraphics{https://static.e-olymp.com/content/b2/b21a542aed24f18e658e204995f0e36d23e040ae.jpg} Your task is to write a program that given the initial coniguration of the board, determines which player will win, if both of them play optimally. \InputFile Each test case is described using several lines. The first line contains two integers \textbf{R} and \textbf{C} representing respectively the number of rows and columns of the board (\textbf{1} ≤ \textbf{R}, \textbf{C} ≤ \textbf{50}). The \textbf{i}-th of the next \textbf{R} lines contains a string \textbf{B_i} of \textbf{C }characters that describes the \textbf{i}-th row of the initial board. The \textbf{j}-th character of \textbf{B_i} is either '\textbf{.}' (dot) or the uppercase letter '\textbf{X}', representing that the tile at row \textbf{i} and column \textbf{j} is respectively white or black. Within each test case at least one of the tiles is white. \OutputFile For each test case output a line with an integer representing the number of the player (\textbf{1} or \textbf{2}) who will win the game if both of them play optimally.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
3 4
....
XX.X
...X
3 4
....
.X.X
...X
3 4
....
.X.X
....
1 1
.
1 11
....X......
Вихідні дані #1
2
1
1
1
2
Джерело ACM ICPC Regional Latino America 2012