CF596E.Wilbur and Strings

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Wilbur the pig now wants to play with strings. He has found an nn by mm table consisting only of the digits from 00 to 99 where the rows are numbered 11 to nn and the columns are numbered 11 to mm . Wilbur starts at some square and makes certain moves. If he is at square ( xx , yy ) and the digit dd ( 0<=d<=90<=d<=9 ) is written at position ( xx , yy ), then he must move to the square ( x+adx+a_{d} , y+bdy+b_{d} ), if that square lies within the table, and he stays in the square ( xx , yy ) 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 qq strings that he is worried about. For each string sis_{i} , Wilbur wants to know whether there exists a starting position ( xx , yy ) so that by making finitely many moves, Wilbur can end up with the string sis_{i} written on the white board.

输入格式

The first line of the input consists of three integers nn , mm , and qq ( 1<=n,m,q<=2001<=n,m,q<=200 ) — the dimensions of the table and the number of strings to process, respectively.

Each of the next nn lines contains mm digits from 00 and 99 giving the table itself.

Then follow 1010 lines. The ii -th of them contains the values ai1a_{i-1} and bi1b_{i-1} ( 200<=ai,bi<=200-200<=a_{i},b_{i}<=200 ), i.e. the vector that Wilbur uses to make a move from the square with a digit i1i-1 in it.

There are qq lines that follow. The ii -th of them will contain a string sis_{i} consisting only of digits from 00 to 99 . It is guaranteed that the total length of these qq strings won't exceed 10000001000000 .

输出格式

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

输入输出样例

  • 输入#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 11 by 11 table consisting of the only digit 00 . The only move that can be made is staying on the square. The first string can be written on the white board by writing 00 repeatedly. The second string cannot be written as there is no 22 on the table.

首页