#P40009. 2019 ICPC NCNA Regional Contest J -

2019 ICPC NCNA Regional Contest J -

题目描述

You are given an n−by−n grid where each square is colored either black or white. A grid is correct if all of the following conditions are satisfied:

  • Every row has the same number of black squares as it has white squares.

  • Every column has the same number of black squares as it has white squares.

  • No row or column has 3 or more consecutive squares of the same color.

    </ul>

    Given a grid, determine whether it is correct.

    输入格式

    The first line contains an integer nn (2n242\le n\le 24; nn is even). Each of the next nn lines contains a string of length nn consisting solely of the characters 'B' and 'W', representing the colors of the grid squares.

    输出格式

    If the grid is correct, print the number 11 on a single line. Otherwise, print the number 00 on a single line.

    样例

    输入样例1

    4
    WBBW
    WBWB
    BWWB
    BWBW
    

    输出样例1

    1
    

    输入样例2

    4
    BWWB
    BWBB
    WBBW
    WBWW
    

    输出样例2

    0
    

    输入样例3

    6
    BWBWWB
    WBWBWB
    WBBWBW
    BBWBWW
    BWWBBW
    WWBWBB
    

    输出样例3

    0
    

    输入样例4

    6
    WWBBWB
    BBWWBW
    WBWBWB
    BWBWBW
    BWBBWW
    WBWWBB
    

    输出样例4

    1