#P3235. [HNOI2014] 江南乐
[HNOI2014] 江南乐
Description
Xiao A is a true enthusiast of turn-based games. After winning many world-class awards in turn-based games, one day he suddenly remembered a turn-based game he played in Jiangnan when he was a child.
The rules are as follows. First, a number is given. Then the game system generates game instances. Each game instance contains heaps of stones. Xiao A and his opponent take turns. On each turn, the player first chooses a positive integer ( is chosen by the player, and can differ from turn to turn, but cannot exceed the number of stones in the chosen heap). Then the player selects any heap with at least stones and splits it into heaps, such that among these heaps, the largest size is at most greater than the smallest size (i.e., as evenly as possible; in fact, under this splitting rule, once and a heap are fixed, the resulting state is determined). A player who cannot move, that is, when every heap has strictly fewer than stones, loses. Supplement: After the first player chooses one of the heaps with at least stones and splits it into heaps, there are heaps in total. Next, Xiao A chooses one of these heaps with at least stones, and so on.
Xiao A has always been a courteous boy, and he invites his opponent to move first. Now Xiao A wants to know, given each game instance and assuming his opponent is just as clever as he is, who will win.
Input Format
The first line contains two positive integers and , denoting the number of game instances and the given number, respectively.
Each of the next lines describes one game instance. In each line, the first number is the number of initial heaps. Then follow positive integers, giving the sizes of these heaps.
Output Format
Output one line containing numbers separated by single spaces. For each game instance, output if Xiao A (the second player) will win, and if Xiao A’s opponent (the first player) will win.
4 3
1 1
1 2
1 3
1 5
0 0 1 1
Hint
For of the testdata, , , , and each heap size .
All the above numbers are positive integers.
Translated by ChatGPT 5
京公网安备 11011102002149号