P2575 Clash of Masters

Description

AKN got tired of playing video games, so he started a game of checkers with his teammate. The opponent is wwx. When these two ancient masters meet over the board, the game becomes unpredictable. When masters clash, there will be a winner. They both play optimally. You are given an $n \times 20$ board with some pieces on it. Who wins? AKN moves first. The rules of the game are as follows: - For any piece, you may move it one cell to the right. If there is a piece immediately to its right, then jump to the first empty cell to the right. If there is no empty cell to the right, you cannot move this piece. If none of the pieces can move, you lose the game.

Input Format

The first line contains $T$, the number of test cases. For each test case, the first line contains $n$, indicating an $n \times 20$ board. Then follow $n$ lines; on each line, the first number $m$ indicates that row $i$ has $m$ pieces. It is then followed by $m$ numbers $p_j$ describing the piece positions in row $i$.

Output Format

If AKN can win, print `YES`; otherwise, print `NO`.

Explanation/Hint

$10\%$ of the testdata has $T \leq 1, n \leq 1$. Additionally, $10\%$ of the testdata has $m \leq 1$. For $100\%$ of the testdata, $T \leq 100$, $n \leq 1000$, $m \leq 20$, $1 \leq p_j \leq 20$. Translated by ChatGPT 5