问题 E: Bitmap

问题 E: Bitmap

时间限制: 2 Sec  内存限制: 256 MB
提交: 87  解决: 27
[状态] [讨论版] [提交] [命题人:]
题目描述
RSYJ is a computer scientist. He has developed many useful image search tools. But now he has encountered some problems.
We use a matrix H × H of to represent a bitmap with H × H size, and each pixel of the 8‑bit bitmap is represented by the integer between [0, 255].
Now, RSYJ have a 8‑bit bitmap A with m × m size, and a 8‑bit bitmap B with m × m size.RSYJ uses an image processing software to copy bitmap B to some positions in bitmap A. Due to RSYJ’s computer’s error, the value of each pixel in the bitmap B is added with an offset k, which is an integer, but RSYJ doesn’t know what  k is.
Now your task is writing a program to help RSYJ find all positions of bitmap B in the bitmap A. To simplify the problem, you only need output how many positions of bitmap B in bitmap A.
For example, here are two bitmaps A and B :
A:
10 9 3
11 6 5
15 7 2
B:
4 3
5 0
Bitmap B was added with an offset 6. It becomes:
10 9
11 6
Bitmap B was added with an offset 2. It becomes:
6 5
7 2
So there are two positions of bitmap B in bitmap A.
输入

The first line of the input gives two positive integers n,m , representing the size of bitmap A and the size of bitmap B, respectively.
The next n lines give the bitmap A. Each line contains n integers.
The next m lines give the bitmap B. Each line contains m  integers.
(1 ≤ n ≤ 2000 , 1 ≤ m ≤ 1000,  0 ≤ aij ≤ 255,  0 ≤ bij ≤ 255 )
输出
Please output an integer, representing the number of positions of bitmap B in bitmap A.
样例输入 Copy
3 2
1 2 9
3 4 7
5 6 0
3 4
5 6
样例输出 Copy
2