#P1191. Counting White Rectangles
Counting White Rectangles
Counting White Rectangles
You are given an \(n \times n\) matrix where each cell is colored either white or black. Your task is to count the number of subrectangles (i.e., contiguous rectangular regions) that are composed entirely of white cells.
Note: A subrectangle is defined by choosing two rows and two columns \( (r_1, r_2, c_1, c_2) \) with \( 0 \le r_1 \le r_2 < n \) and \( 0 \le c_1 \le c_2 < n \) such that every cell \( (r, c) \) with \( r_1 \le r \le r_2 \) and \( c_1 \le c \le c_2 \) is white. The formulas used: the total number of subrectangles if all cells are white is given by \( \frac{n(n+1)}{2} \times \frac{n(n+1)}{2} \), but here some cells may be black.
inputFormat
The first line contains an integer \(n\) (the dimensions of the matrix). The next \(n\) lines each contain a string of length \(n\) consisting of the characters 'W' and 'B', where 'W' denotes a white cell and 'B' denotes a black cell.
outputFormat
Output a single integer which is the total number of subrectangles that contain only white cells.
sample
2
WW
WW
9