Grid and Numbers Game
시간 제한2초메모리 제한2048 MB
서로 인접한 두 수가 같지 않은 N x M 격자에서 두 사람이 번갈아 한 칸의 수를 1 줄이며, 더 이상 합법적인 수가 없는 사람이 지는 게임에서 선수가 이기는지 판정한다.
문제
Busy Beaver and Calico Bear are playing a game with an by grid of nonnegative integers , where initially no two edge-adjacent numbers are equal.
In a move, a player chooses a positive integer in the grid and decreases it by , subject to the constraint that after the move, it still holds that no two edge-adjacent numbers are equal and that all numbers are non-negative. If a player has no legal moves on their turn, they lose, and the other player wins.
Busy Beaver moves first, and then the players alternate. Assuming both players play optimally, determine whether or not Busy Beaver has a winning strategy.
입력
Each test contains multiple test cases. The first line of input contains a single integer () --- the number of test cases. The description of each test case follows.
The first line of each test case contains two positive integers and () --- the dimensions of the grid.
The -th of the next lines contains space-separated nonnegative integers (), where represents the integer in the grid in row and column .
The sum of over all test cases does not exceed .
출력
For each test case, output "Yes" (without quotes) if Busy Beaver wins, and "No" (without quotes) if Calico Bear wins.
힌트
In the first test case, Busy Beaver can decrease the to a . Then, Calico Bear has no moves, so Busy Beaver has a winning strategy.
In the second test case, Busy Beaver has no legal moves. Therefore, Calico Bear has a winning strategy.
In the third test case, Busy Beaver first decreases the central to a . Then, regardless of which Calico Bear decreases, Busy Beaver can decrease the other one. Therefore, Calico Bear runs out of moves before Busy Beaver does, giving Busy Beaver a winning strategy.