Grid and Numbers Game

시간 제한2초메모리 제한2048 MB

요약
서로 인접한 두 수가 같지 않은 N x M 격자에서 두 사람이 번갈아 한 칸의 수를 1 줄이며, 더 이상 합법적인 수가 없는 사람이 지는 게임에서 선수가 이기는지 판정한다.
난이도

어려움10점 중 8점

유형
게임 이론, 그리디, 수학
정답자
아직 제출이 없습니다

문제

Busy Beaver and Calico Bear are playing a game with an NN by MM grid of nonnegative integers a_i,ja\_{i,j}, 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 11, 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 TT (1≤T≤1041 \leq T \leq 10^4) --- the number of test cases. The description of each test case follows.

The first line of each test case contains two positive integers NN and MM (1≤N,M,N⋅M≤2.5⋅1051 \leq N, M, N \cdot M \leq 2.5 \cdot 10^5) --- the dimensions of the grid.

The ii-th of the next NN lines contains MM space-separated nonnegative integers a_i,1,…,a_i,Ma\_{i,1}, \dots, a\_{i,M} (0≤a_i,j≤1090 \leq a\_{i,j} \leq 10^9), where a_i,ja\_{i,j} represents the integer in the grid in row ii and column jj.

The sum of N⋅MN \cdot M over all test cases does not exceed 2.5⋅1052.5 \cdot 10^5.

출력

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 11 to a 00. 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 33 to a 22. Then, regardless of which 1010 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.

예제1

  1. 예제 1

    입력
    5
    1 1
    1
    1 5
    0 1 2 3 4
    3 3
    0 1 0
    10 3 10
    0 1 0
    2 4
    0 2 4 6
    1 3 5 7
    4 5
    6 7 6 7 6
    7 6 7 6 7
    6 7 6 7 6
    7 6 7 6 7
    
    예상 출력
    Yes
    No
    Yes
    No
    No