A8707 | Quick Tortoise
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
John Doe has a field, which is a rectangular table of size $n×m$ . We assume that the field rows are numbered from 1 to $n$ from top to bottom, and the field columns are numbered from 1 to $m$ from left to right. Then the cell of the field at the intersection of the $x$ -th row and the $y$ -th column has coordinates ( $x$ ; $y$ ).
We know that some cells of John's field are painted white, and some are painted black. Also, John has a tortoise, which can move along the white cells of the field. The tortoise can get from a white cell with coordinates ( $x$ ; $y$ ) into cell ( $x+1$ ; $y$ ) or ( $x$ ; $y+1$ ), if the corresponding cell is painted white. In other words, the turtle can move only along the white cells of the field to the right or down. The turtle can not go out of the bounds of the field.
In addition, John has $q$ queries, each of them is characterized by four numbers $x_{1},y_{1},x_{2},y_{2}$ ( $x_{1}<=x_{2}$ , $y_{1}<=y_{2}$ ). For each query John wants to know whether the tortoise can start from the point with coordinates ( $x_{1}$ ; $y_{1}$ ), and reach the point with coordinates ( $x_{2}$ ; $y_{2}$ ), moving only along the white squares of the field.
We know that some cells of John's field are painted white, and some are painted black. Also, John has a tortoise, which can move along the white cells of the field. The tortoise can get from a white cell with coordinates ( $x$ ; $y$ ) into cell ( $x+1$ ; $y$ ) or ( $x$ ; $y+1$ ), if the corresponding cell is painted white. In other words, the turtle can move only along the white cells of the field to the right or down. The turtle can not go out of the bounds of the field.
In addition, John has $q$ queries, each of them is characterized by four numbers $x_{1},y_{1},x_{2},y_{2}$ ( $x_{1}<=x_{2}$ , $y_{1}<=y_{2}$ ). For each query John wants to know whether the tortoise can start from the point with coordinates ( $x_{1}$ ; $y_{1}$ ), and reach the point with coordinates ( $x_{2}$ ; $y_{2}$ ), moving only along the white squares of the field.
输入格式
The first line contains two space-separated integers $n$ and $m$ ( $1<=n,m<=500$ ) — the field sizes.
Each of the next $n$ lines contains $m$ characters "\#" and ".": the $j$ -th character of the $i$ -th line equals "\#", if the cell ( $i$ ; $j$ ) is painted black and ".", if it is painted white.
The next line contains integer $q$ ( $1<=q<=6·10^{5})$ — the number of queries. Next $q$ lines contain four space-separated integers $x_{1}$ , $y_{1}$ , $x_{2}$ and $y_{2}$ ( $1<=x_{1}<=x_{2}<=n$ , $1<=y_{1}<=y_{2}<=m$ ) — the coordinates of the starting and the finishing cells. It is guaranteed that cells ( $x_{1}$ ; $y_{1}$ ) and ( $x_{2}$ ; $y_{2}$ ) are white.
Each of the next $n$ lines contains $m$ characters "\#" and ".": the $j$ -th character of the $i$ -th line equals "\#", if the cell ( $i$ ; $j$ ) is painted black and ".", if it is painted white.
The next line contains integer $q$ ( $1<=q<=6·10^{5})$ — the number of queries. Next $q$ lines contain four space-separated integers $x_{1}$ , $y_{1}$ , $x_{2}$ and $y_{2}$ ( $1<=x_{1}<=x_{2}<=n$ , $1<=y_{1}<=y_{2}<=m$ ) — the coordinates of the starting and the finishing cells. It is guaranteed that cells ( $x_{1}$ ; $y_{1}$ ) and ( $x_{2}$ ; $y_{2}$ ) are white.
输出格式
For each of $q$ queries print on a single line "Yes", if there is a way from cell ( $x_{1}$ ; $y_{1}$ ) to cell ( $x_{2}$ ; $y_{2}$ ), that meets the requirements, and "No" otherwise. Print the answers to the queries in the order, in which the queries are given in the input.
输入输出样例
输入 #1
3 3 ... .## .#. 5 1 1 3 3 1 1 1 3 1 1 3 1 1 1 1 2 1 1 2 1
输出 #1
No Yes Yes Yes Yes
输入 #2
5 5 ..... .###. ..... .###. ..... 5 1 1 5 5 1 1 1 5 1 1 3 4 2 1 2 5 1 1 2 5
输出 #2
Yes Yes Yes No Yes
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted