시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 1024 MB 2 1 1 50.000%

문제

A robot race on a maze will be held in Byteland. The maze has a shape of a rectangle and is divided into $n \times m$ fields arranged in $n$ rows and $m$ columns. Each of the fields is either empty or contains an obstacle.

The contestants register their robots for the competition and come to the maze one after another. Each of the contestants gets random coordinates of the initial field and the target field. The robot is then placed in the initial field and must get to the target field using a sequence of steps.

To make the game more challenging, the rules specify that in each step the robot can only move one field right or one field down in the maze. Moving the robot in any other direction is not allowed.

The contestant whose robot gets fastest from the initial field to the target field wins the competition. If the robot does not get to the target field in the time limit, the contestant in disqualified.

The organizers of the competition realized that if the contestant gets bad coordinates, the robot will not be able to get to the target field using any sequence of moves. In that case they would like to give the contestant another pair of coordinates.

You are given a map of a maze of size $n \times m$ and $q$ pairs of coordinates of the initial and target fields. Determine for each pair of coordinates whether it is possible to get from the initial field to the target field using a sequence of steps right or down.

입력

The first line contains three integers $n$, $m$ and $q$: the number of rows and columns of the maze and the number of pairs of coordinates.

Each of the following $n$ lines contains $m$ characters describing the fields of the maze. The character . represents an empty field and the character # a field with an obstacle.

Then $q$ lines follow describing the pairs of coordinates. The $i$-th of them contains four integers ${r_1}_i$, ${c_1}_i$, ${r_2}_i$, ${c_2}_i$: the row and the column of the initial field and the row and the column of the target field.

• It holds $1 \leq n, m \leq 1000$ and $1 \leq q \leq 10^6$.
• For all $i \in \{ 1, 2, \ldots, q \}$ it holds $1 \leq {r_1}_i, {r_2}_i \leq n$ and $1 \leq {c_1}_i, {c_2}_i \leq m$.
• For all $i \in \{ 1, 2, \ldots, q \}$ the fields in the maze with coordinates $({r_1}_i, {c_1}_i)$ and $({r_2}_i, {c_2}_i)$ are empty.
• Furthermore, in 20 % of the testcases $q \leq 300$.

출력

Output $q$ lines. The $i$-th line should contain the word YES if the robot can get from the $i$-th initial field to the $i$-th target field, or the word NO otherwise.

예제 입력 1

3 4 5
.#..
.##.
....
1 1 3 4
1 3 3 4
1 1 1 1
1 1 2 4
2 1 2 4


예제 출력 1

YES
YES
YES
NO
NO
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.40677276253700256, "perplexity": 894.0090417154203}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-09/segments/1550247479967.16/warc/CC-MAIN-20190216065107-20190216091107-00372.warc.gz"}