Clever Cell Choices

시간 제한6초메모리 제한1024 MB

요약
양쪽이 최선을 다할 때, 빈 칸 중 선공이 이기는 시작 칸의 개수를 센다.
난이도

어려움10점 중 8점

유형
게임 이론, 그래프, DFS, 조합론
정답자
아직 제출이 없습니다

문제

Two players play the following game on an N×MN \times M grid:

  • Initially each cell of the grid is either empty or occupied.
  • Players take turns placing a stone on an empty cell, occupying the cell. Each new stone must be adjacent to the last placed stone, with the exception of the starting stone that can be placed on any empty cell. A stone is adjacent to another stone if they are located in two cells that share a side.
  • The game ends whenever a player cannot place a stone according to the above rules. In that case, the player who cannot place a stone loses the game, and the other player wins.

A winning starting cell is a cell such that the first player wins the game if they place their starting stone there, assuming both players play optimally. Given a description of the initial grid, you must tell how many winning starting cells it has.

입력

The first line contains two integers NN and MM (1≤N,M≤501 ≤ N, M ≤ 50) indicating the dimensions of the grid.

Each of the next NN lines contains a string of length MM. In the ii-th string, the jj-th character describes the initial state of cell (i,j)(i, j). The character is either “.” (dot) denoting an empty cell, or “#” (hash) representing an occupied cell.

출력

Output a single line with an integer indicating the number of winning starting cells.

예제3

  1. 예제 1

    입력
    3 3
    #.#
    ...
    #.#
    
    예상 출력
    4
    
  2. 예제 2

    입력
    3 3
    ..#
    ...
    ...
    
    예상 출력
    0
    
  3. 예제 3

    입력
    1 4
    ...#
    
    예상 출력
    2