#K34452. Taco Grid Valid Position Count
Taco Grid Valid Position Count
Taco Grid Valid Position Count
You are given a grid with N rows and M columns. Your task is to determine the number of valid positions where the '@' character can be placed such that it is surrounded by empty cells on the top, bottom, left, and right sides.
A position is considered valid if it is not on the boundary of the grid. In other words, if a valid position is represented by coordinates \((i, j)\), then the condition must be satisfied: \(2 \leq i \leq N-1\) and \(2 \leq j \leq M-1\).
Calculation: If \(N \geq 3\) and \(M \geq 3\), then the number of valid positions is given by the formula:
[ \text{ValidPositions} = (N-2)(M-2) ]
Otherwise, if either N or M is less than 3, no valid positions exist, and the answer is 0.
inputFormat
The input is read from standard input (stdin
) and consists of two space-separated integers:
- N: the number of rows in the grid.
- M: the number of columns in the grid.
You may assume that these values are provided on a single line.
outputFormat
Output a single integer to standard output (stdout
): the number of valid positions where '@' can be placed according to the given rules.
3 3
1