#P16010. [CCO 2016 Day 2] O Canada

[CCO 2016 Day 2] O Canada

题目描述

In this problem, a grid is an NN-by-NN array of cells, where each cell is either red or white.

Some grids are similar to other grids. Grid AA is similar to grid BB if and only if AA can be transformed into BB by some sequence of changes. A change consists of selecting a 22-by-22 square in the grid and flipping the colour of every cell in the square. (Red cells in the square will become white; white cells in the square will become red.)

You are given GG grids. Count the number of pairs of grids which are similar. (Formally, number the grids from 11 to GG, then count the number of tuples (i,j)(i, j) such that 1i<jG1 \le i < j \le G and grid ii is similar to grid jj.)

输入格式

The first line of input contains N (2N10)N\ (2 \le N \le 10), the size of the grids. The second line contains G (2G10000)G\ (2 \le G \le 10\,000), the number of grids. The input then consists of NGN \cdot G lines, where each line contains NN characters, where each character is either R or W, indicating the colour (red or white) for that element in the grid. Moreover, after the first two lines of input, the next NN lines describe the first grid, the following NN lines describe the second grid, and so on.

For 1212 out of the 2525 marks available for this question, 2G102 \le G \le 10.

输出格式

Output the number of pairs of grids which are similar.

2
2
RW
WR
WR
RW
1

提示

There are exactly two grids, and they are similar because the first grid can be transformed into the second grid using one change (selecting the 22-by-22 square consisting of the entire grid).