#P4398. [JSOI2008] Blue Mary的战役地图

    ID: 3309 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2008各省省选江苏枚举,暴力哈希,HASH

[JSOI2008] Blue Mary的战役地图

Description

Blue Mary has recently become hooked on playing StarCraft RPGs. She is trying to find more campaign maps to further improve her skills.

Since Blue Mary has reached a certain skill level, for campaign maps that can be cleared using the same strategy, she only needs to play one of them to learn that type of strategy, and then she loses interest in other maps of the same type. Many maps circulating online share the same strategy, so Blue Mary needs you to write a program to help her determine which maps belong to the same type.

Specifically, Blue Mary has encoded each campaign map as an n×nn \times n matrix, where each cell contains a positive 32-bit (signed) integer. For two matrices, their similarity is defined as the side length of their largest common square submatrix. The greater the similarity between two matrices, the more likely the two campaign maps are of the same type.

Input Format

The first line contains a positive integer nn.

The next nn lines each contain nn positive integers, representing the matrix of the first campaign map.

The following nn lines each contain nn positive integers, representing the matrix of the second campaign map.

Output Format

Output a single line containing one positive integer, which is the similarity between the two matrices.

3
1 2 3
4 5 6
7 8 9
5 6 7
8 9 1
2 3 4
2

Hint

Sample explanation:

Submatrix: $\begin{bmatrix} 5 & 6 \\ 8 & 9 \\ \end{bmatrix}$ is the largest common submatrix of the two maps.

Constraints: n50n \le 50.

Translated by ChatGPT 5