#P1583C. Omkar and Determination
Omkar and Determination
No submission language available for this problem.
Description
The problem statement looms below, filling you with determination.
Consider a grid in which some cells are empty and some cells are filled. Call a cell in this grid exitable if, starting at that cell, you can exit the grid by moving up and left through only empty cells. This includes the cell itself, so all filled in cells are not exitable. Note that you can exit the grid from any leftmost empty cell (cell in the first column) by going left, and from any topmost empty cell (cell in the first row) by going up.
Let's call a grid determinable if, given only which cells are exitable, we can exactly determine which cells are filled in and which aren't.
You are given a grid of dimensions , i. e. a grid with rows and columns. You need to answer queries (). Each query gives two integers () and asks whether the subgrid of consisting of the columns is determinable.
The first line contains two integers (, ) — the dimensions of the grid .
lines follow. The -th line contains characters, the -th of which is 'X' if the cell on the intersection of the the -th row and -th column is filled and "." if it is empty.
The next line contains a single integer () — the number of queries.
lines follow. Each line contains two integers and (), representing a query asking whether the subgrid of containing the columns is determinable.
For each query, output one line containing "YES" if the subgrid specified by the query is determinable and "NO" otherwise. The output is case insensitive (so "yEs" and "No" will also be accepted).
Input
The first line contains two integers (, ) — the dimensions of the grid .
lines follow. The -th line contains characters, the -th of which is 'X' if the cell on the intersection of the the -th row and -th column is filled and "." if it is empty.
The next line contains a single integer () — the number of queries.
lines follow. Each line contains two integers and (), representing a query asking whether the subgrid of containing the columns is determinable.
Output
For each query, output one line containing "YES" if the subgrid specified by the query is determinable and "NO" otherwise. The output is case insensitive (so "yEs" and "No" will also be accepted).
Samples
Note
For each query of the example, the corresponding subgrid is displayed twice below: first in its input format, then with each cell marked as "E" if it is exitable and "N" otherwise.
For the first query:
..X EEN
... EEE
... EEE
... EEE
For the second query:
X N
. E
. E
. E
Note that you can exit the grid by going left from any leftmost cell (or up from any topmost cell); you do not need to reach the top left corner cell to exit the grid.
For the third query:
XX NN
X. NN
X. NN
X. NN
This subgrid cannot be determined only from whether each cell is exitable, because the below grid produces the above "exitability grid" as well:
XX
XX
XX
XX
For the fourth query:
X N
. E
. E
. E
For the fifth query:
..XXX EENNN
...X. EEENN
...X. EEENN
...X. EEENN
This query is simply the entire grid. It cannot be determined only from whether each cell is exitable because the below grid produces the above "exitability grid" as well:
..XXX
...XX
...XX
...XX