#C7136. Valley Cell Counter
Valley Cell Counter
Valley Cell Counter
You are given a grid with N rows and M columns where each cell contains an integer representing its height. A cell is defined as a valley if its value is strictly less than the values of all of its four direct neighbors (top, bottom, left, right). Mathematically, if a cell at position (i, j) has height h and its neighbors have heights h_1, h_2, h_3, h_4, then the cell is a valley if
[ h < h_1, \quad h < h_2, \quad h < h_3, \quad h < h_4 ]
Your task is to count and output the number of valley cells in the grid.
inputFormat
The first line of input contains two integers N and M (1 ≤ N, M ≤ 2000), representing the number of rows and columns respectively. This is followed by N lines, each containing M integers which represent the heights in the grid.
outputFormat
Output a single integer: the number of valley cells in the grid.## sample
3 3
5 4 5
4 1 4
5 4 5
1