logo AlgoBeat OnlineJudge
登录 注册

#206104. [ICPC 2021 WF] Mosaic Browsing

内存限制:256 MiB 时间限制:6000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The International Center for the Preservation of Ceramics (ICPC) is searching for motifs in some ancient mosaics. According to the ICPC's definition, a is a rectangular grid where each grid square contains a colored tile. A is similar to a mosaic but some of the grid squares can be empty. Figure G.1 shows an example motif and mosaic.

The rows of an mosaic are numbered to from top to bottom, and the columns are numbered to from left to right.

A contiguous rectangular subgrid of the mosaic matches the motif if every tile of the motif matches the color of the corresponding tile of the subgrid. Formally, an motif appears in an mosaic at position (, ) if for all , , the tile (, ) exists in the mosaic and either the square (, ) in the motif is empty or the tile at (, ) in the motif has the same color as the tile at (, ) in the mosaic.

Given the full motif and mosaic, find all occurrences of the motif in the mosaic.

Figure G.1: Motif (left) and mosaic (right) of Sample Input 1.

输入格式

The first line of input contains two integers and , where and () are the number of rows and columns in the motif. Then lines follow, each with integers in the range , denoting the color of the motif at that position. A value of denotes an empty square.

The next line of input contains two integers and where and () are the number of rows and columns in the mosaic. Then lines follow, each with integers in the range , denoting the color of the mosaic at that position.

输出格式

On the first line, output , the total number of matches. Then output lines, each of the form where is the row and is the column of the top left tile of the match. Sort matches by increasing , breaking ties by increasing .

样例

样例输入 1

2 2
1 0
0 1
3 4
1 2 1 2
2 1 1 1
2 2 1 3

样例输出 1

3
1 1
1 3
2 2