The Big Picture
Time limit2sMemory limit512 MB
Count the top-left positions where the given black-and-white painting matches the masterpiece exactly without rotation.
- Level
Medium7 of 10
- Topics
- String matching
- Solved
- No attempts yet
Problem
Jaehyuk is a painter with no money, not even a board to paint on. So he decided to sew his unsold paintings together into one large picture, and after a full day of work he finished a masterpiece.
One day a buyer called and asked for one of the paintings that had not been sold. Jaehyuk never wrote down which paintings went into the masterpiece, so he has to find where that painting ended up.
You are given one painting and the masterpiece, both drawn in black and white. Count how many positions of the masterpiece the painting appears at. The painting was glued in exactly as it is, so it is never rotated or flipped, and one position is one top left coordinate at which every cell of the painting equals the cell of the masterpiece under it. Positions that overlap are counted separately.
Input
The first line contains the integers , , , , separated by spaces. They are the height and the width of the painting, then the height and the width of the masterpiece.
The next lines contain the painting, characters per line. The following lines contain the masterpiece, characters per line. Both pictures consist only of the characters 'o' and 'x'.
and .
Output
Print the number of positions where the painting appears in the masterpiece, on one line.