CF232E.Quick Tortoise

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

约翰·多伊尔有一块田地,其形状为一个 n×mn \times m 的矩形表格。我们假设田地的行从上到下编号为 11 到 nn,列从左到右编号为 11 到 mm。那么位于第 xx 行与第 yy 列交点处的格子坐标为 (x;y)(x; y)。

已知约翰的田地中,部分格子被涂成白色,其余被涂成黑色。此外,约翰还拥有一只乌龟,它只能在白色格子上移动。乌龟可以从坐标为 (x;y)(x; y) 的白色格子移动到 (x+1;y)(x+1; y) 或 (x;y+1)(x; y+1) 所在的格子,前提是目标格子也为白色。换言之,乌龟只能在白色格子上向右或向下移动,且不能移出田地边界。

此外,约翰有 qq 个查询,每个查询由四个整数 x1, y1, x2, y2x_1,\ y_1,\ x_2,\ y_2 描述(满足 x1≤x2x_1 \le x_2 且 y1≤y2y_1 \le y_2)。对于每个查询,约翰想知道:乌龟能否从坐标为 (x1;y1)(x_1; y_1) 的起点出发,仅经过白色格子,最终到达坐标为 (x2;y2)(x_2; y_2) 的终点?

输入格式

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·105) — 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.

第一行包含两个用空格分隔的整数 nn 和 mm(1≤n,m≤5001 \leq n, m \leq 500)——表示网格的尺寸。

接下来的 nn 行,每行包含 mm 个字符 "#" 或 ".":第 ii 行的第 jj 个字符为 "#",表示单元格 (i,j)(i, j) 被涂成黑色;为 ".",表示该单元格被涂成白色。

下一行包含一个整数 qq(1≤q≤6⋅1051 \leq q \leq 6 \cdot 10^5)——表示查询次数。随后的 qq 行,每行包含四个用空格分隔的整数 x1x_1、y1y_1、x2x_2 和 y2y_2(1≤x1≤x2≤n1 \leq x_1 \leq x_2 \leq n,1≤y1≤y2≤m1 \leq y_1 \leq y_2 \leq m)——分别表示起始单元格与结束单元格的坐标。保证单元格 (x1,y1)(x_1, y_1) 和 (x2,y2)(x_2, y_2) 均为白色。

输出格式

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.

对于每个查询,如果存在一条从单元格 (x1,y1)(x_1, y_1) 到单元格 (x2,y2)(x_2, y_2) 的路径,且该路径满足题目要求,则在单独一行输出“Yes”;否则输出“No”。请按照输入中查询给出的顺序输出各查询的答案。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页