#P10937. Non-Attacking Chariots

    ID: 12985 Type: Default 1000ms 256MiB

Non-Attacking Chariots

Non-Attacking Chariots

Given an \(N\) \(\times\) \(M\) board, some cells are forbidden for placement. You are asked to place as many chariots as possible such that no two chariots attack each other. A chariot placed on a cell attacks in the same manner as the "\(\text{車}\)" (chariot) in Chinese chess, i.e. it can move horizontally or vertically along unobstructed lines. Obstacles (forbidden cells) block the line of attack.

You are given the board configuration where each cell is represented by a character. A cell containing a . denotes a cell where a chariot can be placed; a cell containing an X denotes a forbidden cell where placement is not allowed.

Your task is to compute the maximum number of chariots that can be placed on the board so that no two of them attack each other.

Note: Two chariots attack each other if they are in the same contiguous row segment (cells in the same row between obstacles) or the same contiguous column segment (cells in the same column between obstacles) without any forbidden cell in between.

inputFormat

The input consists of:

  1. The first line contains two space-separated integers \(N\) and \(M\) denoting the number of rows and columns respectively.
  2. The next \(N\) lines each contain a string of length \(M\) composed of characters . (allowed cell) and X (forbidden cell).

It is guaranteed that \(N\) and \(M\) are positive integers.

outputFormat

Output a single integer representing the maximum number of non-attacking chariots that can be placed on the board.

sample

3 3
...
.X.
...
4

</p>