문제
Bessie and her friends have invented a new game. The game is named accurately, but not particularly creatively. They call it the "Push A Box Around The Barn To Get It In The Right Spot And Don't Move The Hay" game (if you think that's excessive, you should see some of the variable names the cows use when they write code...)
The barn can be modeled as an
Bessie can move in the 4 orthogonal directions (north, east, south, west) as long as she does not walk into hay. If she attempts to walk to the space with the box, then the box will be pushed one space in that direction, as long as there is an empty cell on the other side. If there is no empty cell, then Bessie will not be able to make that move.
A certain grid cell is designated as the goal. Bessie's goal is to get the box into that location.
Given the layout of the barn, including the starting positions of the box and the cow, and the target position of the box, determine if it possible to win the game.
Note: This problem allows 512MB of memory usage, up from the default limit of 256MB.
Problem credits: Nathan Pinsker
입력
The first line has three numbers,
1 \le N,M \le 1500 .1 \le Q \le 50,000 .
On the next
This is followed by
출력
예제
5 5 4
##.##
##.##
A.B..
##.##
##.##
3 2
3 5
1 3
5 3
NO
YES
NO
NO
To push the box to the position (3, 5), the cow just needs to move 3 spaces to the right.
None of the other three positions are attainable.