Piece Chessboard
Time limit2sMemory limit1024 MB
Count the square subgrids of an N by M black/white grid whose cells alternate colors like a chessboard.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Prefix sum, Matrix, Implementation
- Solved
- No attempts yet
Problem
A square grid of height and width has each cell painted either black or white. Hyeonchae, whose head is full of chess, wonders how many ways there are to cut this grid so that the result is a chessboard.
A chessboard must have black and white painted alternately. Specifically, each cell is painted one of black and white, and any two squares that share an edge must be painted different colors. The shape of a chessboard must be a square, and it does not have to be .
Let us satisfy Hyeonchae's curiosity.
Input
The input is given as follows.
- is a character meaning the color painted on , and it is one of
BandW. If isB, then is painted black, and if it isW, then is painted white.
Output
Output how many ways there are to cut the given grid so that the result is a chessboard.