#350
Unrated
Push a Box
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 N×MN \times M rectangular grid. Some of the grid cells have hay in them. Bessie occupies one cell in this grid, and a large wooden box occupies another cell. Bessie and the box are not able to fit in the same cell at the same time, and neither can fit into a cell containing hay.

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.

입력

The first line has three numbers, NN, MM, and QQ, where NN is the number of rows in the grid and MM is the number of columns.

1N,M15001 \le N,M \le 1500.

1Q50,0001 \le Q \le 50,000.

On the next NN lines is a representation of the grid, where characters represent empty cells (.), hay (#), Bessie's starting position (A), and the box's initial location (B).

This is followed by QQ lines, each with a pair of integers (R,C)(R, C). For each pair, you should determine if it is possible to get the box to that cell at row RR, column CC, starting from the initial state of the barn. The top row is row 1, and the left column is column 1.

출력

QQ lines, each with either the string "YES" or "NO".

예제 입력 1

5 5 4
##.##
##.##
A.B..
##.##
##.##
3 2
3 5
1 3
5 3

예제 출력 1

NO
YES
NO
NO
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.