시간 제한메모리 제한제출정답맞힌 사람정답 비율
40 초 (추가 시간 없음) 1024 MB (추가 메모리 없음)111100.000%

문제

Izabella and Olga are playing a new game alternating turns. In this game, they personify attraction inventors working for a theme park. The board is a matrix of square cells that illustrates the map of the theme park. Some cells were deemed apt to host a new attraction.

When an attraction is built, signs to advertise it are added automatically. $4$ sign builders are sent in each diagonal direction. The one moving towards the north-east direction proceeds as follows: starting at the cell where the location is built, check the cell north-east from its current cell. If there is no cell there, or the cell is occupied, they stop. Otherwise, they move to that cell, build a sign there, and repeat. Sign builders that move in the north-western, south-eastern and south-western directions proceed the same, except for the direction of the movements. A cell is considered occupied if it contains either an attraction or a sign.

For example, suppose the left picture below represents a map, with yellow cells representing the spots where attractions can be built. After an attraction is built on $3,4$ of the map (now marked with a blue square), signs are also built on cells marked in gray. Some spots that were previously available for attractions are no longer available because they contain a sign now. Notice after a second attraction is built on $3,6$, the new sign builders only move as far as a previous sign, leading to the situation illustrated in the right picture.

In a turn, a player can choose to build an attraction in any available spot, and then the sign builders proceed automatically, possibly invalidating other spots as in the example. The goal of the game is to outlast the opponent: the player that, in her turn, does not have any available spot to build an attraction loses the game.

Izabella plays first. Assuming both players play optimally to win the game, can you count how many different plays on Izabella's first turn would result in her winning?

입력

The first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each test case starts with a line containing two integers $R$ and $C$ representing the number of rows and columns of the board, respectively. Then, $R$ lines follow. The $i$-th of these lines contains a string of $C$ characters $L_{i,1}L_{i,2}\cdots L_{i,C}$. $L_{i,j}$ is an uppercase X if the cell in the $i$-th row and $j$-th column is a spot available for a new attraction, and a period (.) if it is not.

출력

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is an integer representing the number of possible first turn plays that result in Izabella winning the game.

제한

  • $1≤T≤100$.
  • $L_{i,j}$ is either an uppercase X or an period (.), for all $i,j$.

Test Set 1 (12점)

  • $1≤R≤10$.
  • $1≤C≤10$.
  • $L_{i,j}=$ X for at most $10$ combinations of $i,j$. (There are at most 10 Xs in the input matrix.)

Test Set 2 (25점)

  • $1≤R≤100$.
  • $1≤C≤100$.
  • $R×C≤200$.

예제 입력 1

4
5 7
.......
...X.X.
...X.X.
..XX...
..X....
1 5
X.X.X
2 5
X.X.X
.X.X.
2 2
X.
.X

예제 출력 1

Case #1: 1
Case #2: 3
Case #3: 1
Case #4: 2

힌트

In Sample Case #1, the only winning move for Izabella is to put her invented attraction at $(2,4)$. The other $6$ moves lead to a game Olga can win if they both play optimally.

In Sample Case #2, either of the valid first plays for Izabella leads to a board with $2$ remaining spots, and either of the $2$ remaining spot for Olga leads to a board with $1$ remaining spot which is Izabella's winning game. So any of the $3$ valid plays is winning.

In Sample Case #3, only playing in the middle one among $5$ spots is a winning move for Izabella. The other $4$ moves lead to a game Olga can win if they both play optimally.

In Sample Case #4, either of the valid first plays for Izabella leaves no valid play for Olga, so Izabella wins immediately with any of them.

채점 및 기타 정보

  • 예제는 채점하지 않는다.