更好的阅读体验
D. Yet Another Number Game
题目描述
Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland, I’ll give you the chance of peeking at one of these games.
BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They’ve got a sequence of n n n non-negative integers a 1 , a 2 , . . . , a n a_1, a_2, ..., a_n a1, a2, ..., an. The players make moves in turns. BitLGM moves first. Each player can and must do one of the two following actions in his turn:
- Take one of the integers (we’ll denote it as a i a_i ai). Choose integer x x x ( 1 ≤ x ≤ a i 1 \le x \le a_i 1 ≤ x ≤ ai). And then decrease a i a_i ai by x x x, that is, apply assignment: a i a_i ai = a i a_i ai - x x x.
- Choose integer x x x ( 1 ≤ x ≤ m i n i = 1 n a i 1\le x \le min_{i=1}^n a_i 1≤x≤mini=1nai). And then decrease all a i a_i ai by x x x, that is, apply assignment: a i = a i − x a_i = a_i - x ai = ai − x, for all i i i.
The player who cannot make a move loses.
You’re given the initial sequence a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1, a2, …, an. Determine who wins, if both players plays optimally well and if BitLGM and BitAryo start playing the described game in this sequence.
Input
The first line contains an integer n n n ( 1 ≤ n ≤ 3 1 \le n \le 3 1 ≤ n ≤ 3).
The next line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1, a2, …, an ( 0 ≤ a i < 300 0 \le a_i \lt 300 0 ≤ ai < 300).
Output
Write the name of the winner (provided that both players play optimally well). Either “BitLGM” or “BitAryo” (without the quotes).
Example
input1
2
1 1
output1
BitLGM
input2
2
1 2
output2
BitAryo
input3
3
1 2 1
output3
BitLGM
题意
两个人玩取石子游戏,按照如下规则取石子:
- 每次可以选择一堆去掉任意多个。
- 每次选择所有的堆,去掉任意多个(每堆去掉的数量相同)。
不能操作的人为负,BitLGM先手,BitAryo后手,问你谁必胜。
分析
注意到数据范围, 1 ≤ n ≤ 3 , 0 ≤ a i < 300 1\le n\le 3, 0\le a_i \lt 300 1≤n≤3,0≤ai<300
不难看出,这个可以转换为三个子问题。
- 只有一堆
- 只有两堆
- 有三堆。
下面分情况讨论。
只有一堆
不难发现,对于先手来说,我可以直接取走这一堆,所以只要 a 1 ≠ 0 a_1 \ne 0 a1=0 那么必然有先手必胜 。
只有两堆
不难想到的是,我们可以用一个二维数组来判定当前的胜负态,也即:定义 G ( i , j ) G(i, j) <