CF596E.Wilbur and Strings

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Wilbur the pig now wants to play with strings. He has found an n by m table consisting only of the digits from 0 to 9 where the rows are numbered 1 to n and the columns are numbered 1 to m. Wilbur starts at some square and makes certain moves. If he is at square (x, y) and the digit d (0 ≤ d ≤ 9) is written at position (x, y), then he must move to the square (x + a__d, y + b__d), if that square lies within the table, and he stays in the square (x, y) otherwise. Before Wilbur makes a move, he can choose whether or not to write the digit written in this square on the white board. All digits written on the whiteboard form some string. Every time a new digit is written, it goes to the end of the current string.

Wilbur has q strings that he is worried about. For each string s__i, Wilbur wants to know whether there exists a starting position (x, y) so that by making finitely many moves, Wilbur can end up with the string s__i written on the white board.

小猪威尔伯现在想玩字符串游戏。他发现了一个 nn 行 mm 列的表格,其中每个格子仅包含数字 00 到 99,行编号为 11 到 nn,列编号为 11 到 mm。威尔伯从某个格子出发,并执行若干次移动。若他当前位于格子 (x,y)(x, y),且该位置上写的数字为 dd(0≤d≤90 \le d \le 9),则他必须移动到格子 (x+ad,y+bd)(x + a_d, y + b_d)(若该格子仍在表格范围内);否则,他将停留在原格子 (x,y)(x, y)。在每次移动前,威尔伯可选择是否将当前格子中的数字写在白板上。所有写在白板上的数字按书写顺序构成一个字符串;每次新写入一个数字时,它被添加到当前字符串的末尾。

威尔伯有 qq 个他所关心的字符串。对每个字符串 sis_i,威尔伯想知道:是否存在某个起始位置 (x,y)(x, y),使得通过有限次移动,他能在白板上恰好写出字符串 sis_i?

输入格式

The first line of the input consists of three integers n, m, and q (1 ≤ n, m, q ≤ 200) — the dimensions of the table and the number of strings to process, respectively.

Each of the next n lines contains m digits from 0 and 9 giving the table itself.

Then follow 10 lines. The i-th of them contains the values a__i - 1 and b__i - 1 ( - 200 ≤ a__i, b__i ≤ 200), i.e. the vector that Wilbur uses to make a move from the square with a digit i - 1 in it.

There are q lines that follow. The i-th of them will contain a string s__i consisting only of digits from 0 to 9. It is guaranteed that the total length of these q strings won't exceed 1 000 000.

输入的第一行包含三个整数 nn、mm 和 qq(1≤n,m,q≤2001 \leq n, m, q \leq 200),分别表示表格的行数、列数以及需要处理的字符串个数。

接下来的 nn 行,每行包含 mm 个数字(仅由 0 到 9 组成),表示该表格本身。

随后是 10 行。其中第 ii 行包含两个值 ai−1a_{i-1} 和 bi−1b_{i-1}(−200≤ai,bi≤200-200 \leq a_i, b_i \leq 200),即威尔伯在当前格子中数字为 i−1i-1 时所使用的移动向量。

接下来有 qq 行。其中第 ii 行包含一个字符串 sis_i,该字符串仅由数字 0 到 9 组成。保证这 qq 个字符串的总长度不超过 1 000 0001\,000\,000。

输出格式

For each of the q strings, print "YES" if Wilbur can choose x and y in order to finish with this string after some finite number of moves. If it's impossible, than print "NO" for the corresponding string.

对于每个字符串,如果威尔伯能够选择 xx 和 yy,使得经过有限步操作后得到该字符串,则输出 “YES”;否则,对于该字符串输出 “NO”。

输入输出样例

  • 输入#1

    1 1 2
    0
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    1 1
    0000000000000
    2413423432432

    输出#1

    YES
    NO
  • 输入#2

    4 2 5
    01
    23
    45
    67
    0 1
    0 -1
    0 1
    0 -1
    0 1
    0 -1
    0 1
    0 -1
    0 1
    0 -1
    0000000000
    010101011101
    32232232322
    44343222342444324
    6767

    输出#2

    YES
    YES
    YES
    NO
    YES

说明/提示

In the first sample, there is a 1 by 1 table consisting of the only digit 0. The only move that can be made is staying on the square. The first string can be written on the white board by writing 0 repeatedly. The second string cannot be written as there is no 2 on the table.

在第一个样例中,存在一个仅包含数字 0 的 1×11 \times 1 表格。唯一可行的操作是停留在该方格上。第一个字符串可通过重复书写 0 写在黑板上。第二个字符串无法写出,因为表格中不存在数字 2。

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

首页