Gahee, Are You Sleeping There?
Time limit1sMemory limit512 MB
Given a grid with one Gahee rectangle and one pillow rectangle, decide whether the two rectangles overlap, counting hidden pillow parts as overlap.
- Level
Easy3 of 10
- Topics
- Implementation, Geometry, Brute force, Array
- Solved
- No attempts yet
Problem
A pillow and Gahee are in a room. Print whether Gahee is sleeping on the pillow.

Input
The first line gives the room's height and width .
The second line gives Gahee's height and width , and the pillow's height and width .
From the third line to the -th line, strings of length are given.
Each character in the given strings is one of G for Gahee, P for the pillow, or . for an empty cell.
Output
Print 1 if Gahee is sleeping on the pillow, otherwise print 0.
If part of the pillow is hidden by Gahee, then Gahee is sleeping on the pillow.
Constraints
- There is exactly one Gahee and one pillow in the map, and neither spans the room's boundary.
- Cases where Gahee or the pillow is completely hidden are not given.
- Gahee and the pillow are given as rectangles, and each side of a rectangle is parallel to the horizontal or vertical axis.
- Gahee may sleep on top of the pillow or underneath it.