Under construction

Still being built. Things may change

Gahee, Are You Sleeping There?

Time limit1sMemory limit512 MB

Summary
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 RR and width CC.

The second line gives Gahee's height RgR_g and width CgC_g, and the pillow's height RpR_p and width CpC_p.

From the third line to the (R+2)(R+2)-th line, strings of length CC 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

  • 11≤R,C≤10011 \le R, C \le 100
  • 1≤Rg,Rp≤R1 \le R_g, R_p \le R
  • 1≤Cg,Cp≤C1 \le C_g, C_p \le C
  • 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.

Examples3

  1. Example 1

    Input
    11 11
    5 4 6 10
    ....GGGG...
    ....GGGG...
    ....GGGG...
    .PPPGGGGPPP
    .PPPGGGGPPP
    .PPPPPPPPPP
    .PPPPPPPPPP
    .PPPPPPPPPP
    .PPPPPPPPPP
    ...........
    ...........
    
    Expected output
    1
    
  2. Example 2

    Input
    11 11
    11 4 6 10
    ....GGGG...
    ....GGGG...
    ....GGGG...
    .PPPPPPPPPP
    .PPPPPPPPPP
    .PPPPPPPPPP
    .PPPPPPPPPP
    .PPPPPPPPPP
    .PPPPPPPPPP
    ....GGGG...
    ....GGGG...
    
    Expected output
    0
    
  3. Example 3

    Input
    11 11
    4 5 6 10
    .GGGGG.....
    .GGGGG.....
    .GGGGG.....
    .GGGGG.....
    ...........
    PPPPPPPPPP.
    PPPPPPPPPP.
    PPPPPPPPPP.
    PPPPPPPPPP.
    PPPPPPPPPP.
    PPPPPPPPPP.
    
    Expected output
    0