#P3480. Johny's Pebbles Game
Johny's Pebbles Game
Johny's Pebbles Game
Johny and Margaret are playing pebbles. Initially there are a certain number of pebbles on a table, grouped in \(n\) piles arranged from left to right such that for every \(i\) with \(2\le i\le n\), the number of pebbles in the \(i^{th}\) pile is at least as many as in the \((i-1)^{th}\) pile.
On each turn, a player may remove any positive number of pebbles from a single pile. However, after the move the configuration must still satisfy \(a_i\ge a_{i-1}\) for all \(i\ge2\). Johny always starts, but Margaret plays optimally. Your task is to determine whether Johny can force a win given the initial configuration.
Hint: It is useful to represent the configuration in terms of differences. Define \(d_1=a_1\) and for \(i\ge2\), \(d_i=a_i-a_{i-1}\). A move on the \(i^{th}\) pile then reduces \(d_i\) by a positive amount (at most \(d_i\)). This is equivalent to a Nim game where each heap has size \(d_i\), so Johny wins if and only if the Nim-sum \(d_1\oplus d_2\oplus\cdots\oplus d_n\) is nonzero.
inputFormat
The first line contains an integer \(T\), the number of test cases. Each test case consists of two lines:
- The first line contains an integer \(n\), the number of piles.
- The second line contains \(n\) space-separated integers representing the pile sizes in non-decreasing order.
outputFormat
For each test case, output a single line with either "Yes" if Johny can force a win, or "No" otherwise.
sample
1
1
4
Yes