CF596E Wilbur and Strings
Description
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
Input Format
The first line of the input consists of three integers $ n $ , $ m $ , and $ q $ ( $ 1
Output Format
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.
Explanation/Hint
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.