cswork / OA打开练习工作台

OpenAIOA #1

Matching Regions in Two Grids

估计中等可在线判题

考点(AI 标注)网格搜索

In each of the two 01 grids, partition the 1 cells into connected components using up/down/left/right adjacency. Count how many components in the second grid have a full coordinate set exactly equal to some full component in the first grid. This is neither a sub-island check nor a same-shape-after-translation check.

输入格式

The first line contains n m, followed by n lines of the first grid and then n lines of the second grid. Each line has m consecutive 0/1 characters. This site uses 1≤n,m≤200.

输出格式

A single integer, the number of exactly matching components.

样例 1

输入:

3 3
111
100
100
111
100
101

输出:

1

样例 2

输入:

1 2
11
10

输出:

0

样例 3

输入:

2 2
10
01
10
01

输出:

2

样例说明

In Example 1 only the large component matches, so the answer is 1. In Example 2 the second grid is only a proper subset of the first, so the answer is 0. In Example 3 diagonal cells are not connected, so there are two matching components.