Valid Chess Board
Practice
4.7 (6 votes)
Basic programming
Basics of implementation
Easy
Implementation
Math
Problem
56% Success 3084 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a tiled chart paper of N rows and M columns. There are a total of N×M tiles in it. Each tile is colored either black or white. Now, you need to count how many ways are there to cut valid chessboards of size 8×8 out of this chart paper. 

Notes

1. One chessboard is different from another if either of them contains at least one tile which is different from another chessboard.
2. The chess board formation should have distinct colors of adjacent cells i.e. Black/White alternative (regular chessboard rules apply).

Input Format

The first line contains two space-separated integers N and M as input.
In the next N lines, you are given a string of M characters. Each character is either 0 or 1. If it is 0 then the tile color is white, if it is 1 then the tile color is black.

Output Format

In the output, you need to print an integer that denotes the required count as stated in the problem statement.

Constraints

1N,M1000

Sample Input
9 9
010101010
101010101
010101010
101010101
010101010
101010101
010101010
101010101
010101010
Sample Output
4
Explanation

There are four ways to cut the chessboard out of the given chart paper. 

 

Code Editor

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Submissions
Please login to view your submissions
Similar Problems
Points:20
76 votes
Tags:
Ad-HocBasic ProgrammingEasyOpen
Points:20
29 votes
Tags:
ApprovedBasic ProgrammingEasyOpen
Points:20
8 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Editorial

Login to unlock the editorial