info

MAPS OS v1.1.4 © 2025

Glory to the Segtree

Glory to the Algorithm.

YogurtbreadGo home

Login to view input

no submission

Login to submit an answer

Problem Leaderboard

Problem Leaderboard

Yogurtbread

The heroes and the White Demon play a game on an n×m grid. Some cells are initially filled and cannot be used. Players take turns placing a yogurt-bread in an empty cell so that, except for the very first yogurt-bread, each placement must be in a cell adjacent (sharing a side) to the opponent’s immediately previous move. The heroes (Team 1) move first. If a player cannot move on their turn, they lose.

Call an empty cell a Chef cell if, by placing the first yogurt-bread there, the heroes can force a win regardless of how the opponent plays. Given the current board, count the number of Chef cells.

Input

  • The first line contains two integers n and m: the board dimensions.
  • The next n lines each contain a string of length m describing the board.
  • Each character is either '.' (empty) or '#' (filled/blocked).
  • The heroes place the first yogurt-bread on any empty cell.
  • After the first move, each move must be to a cell that shares a side with the cell chosen by the opposing team on the immediately preceding turn.
  • Adjacent means sharing a side (up, down, left, or right).

Output

  • Single integer: the number of Chef cells on the given board.

Notes

  • You cannot place a yogurt-bread on a filled cell ('#').
  • If there are no empty cells, the answer is 0.
  • A move is legal if and only if the chosen cell is empty and (except for the very first move) is adjacent to the opponent’s immediately previous move.

Example 1 Input

3 3
#.#
...
#.#

Example 1 Output

4

Example 2 Input

3 3
..#
...
...

Example 2 Output

0

Example 3 Input

1 4
...#

Example 3 Output

2