Rexdf

The devil is in the Details.

Codeforces Round #173 (Div. 2) Yet Another Number Game

| Comments

D. Yet Another Number Game

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 non-negative integers a1, a2, …, a__n. 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). Choose integer x (1 ≤ x ≤ a__i). And then decrease a__i by x, that is, apply assignment:a__i = a__i - x.
  • Choose integer x . And then decrease all a__i by x, that is, apply assignment: a__i = a__i - x, for all i.   The player who cannot make a move loses. You’re given the initial sequence a1, a2, …, a__n. 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 (1 ≤ n ≤ 3). The next line contains n integers a1, a2, …, a__n (0 ≤ a__i < 300).

Output

Write the name of the winner (provided that both players play optimally well). Either “BitLGM” or “BitAryo” (without the quotes).

Sample test(s)

input

2 1 1

output

BitLGM

input

2 1 2

output

BitAryo

input

3 1 2 1

output

BitLGM


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int tab2[305][305];
int tab3[305][305][305];

int check2(int x,int y)
{
	if(0==x && 0==y)return 1;
	int Min=x<y?x:y;
	for(int i=Min;i>=0;i--)
	  if(1==tab2[x-i][y-i])return 0;
	for(int i=0;i<=y;i++)
	  if(1==tab2[x][i])return 0;
	for(int i=0;i<=x;i++)
	  if(1==tab2[i][y])return 0;
	return 1;
}

void mark2(int x,int y)
{
	for(int i=0;;i++)
	{
		if(x+i>303 || y+i>303)break;
		tab2[x+i][y+i]=0;
	}
	for(int i=0;i<303;i++)
	{
		tab2[x][i]=0;
		tab2[i][y]=0;
	}
	tab2[x][y]=1;
}

void inital2()
{
	memset(tab2,-1,sizeof(tab2));
	//tab2[0][0]=1;
	for(int i=0;i<303;i++)
	  for(int j=0;j<303;j++)
	  {
	  	if(tab2[i][j]!=-1)continue;
	  	if(check2(i,j))
	  	{
	  		mark2(i,j);
	  		mark2(j,i);
	  	}
	  }
	/*
	for(int i=0;i<10;i++)
	{
	  for(int j=0;j<10;j++)
	    cout<<tab2[i][j]<<" ";
	  cout<<endl;
	}
	*/
}

int check3(int x,int y,int z)
{
	if(0==x && 0==y && 0==z)return 1;
	int Min=x<y?x:y;
	Min=Min<z?Min:z;
	for(int i=Min;i>=0;i--)
	  if(1==tab3[x-i][y-i][z-i])return 0;
	for(int i=0;i<=z;i++)
	  if(1==tab3[x][y][i])return 0;
	for(int i=0;i<=y;i++)
	  if(1==tab3[x][i][z])return 0;
	for(int i=0;i<=x;i++)
	  if(1==tab3[i][y][z])return 0;
	return 1;
}

void mark3(int x,int y,int z)
{
	for(int i=0;;i++)
	{
		if(x+i>303 || y+i>303 || z+i>303)break;
		tab3[x+i][y+i][z+i]=0;
	}
	for(int i=0;i<303;i++)
	{
		tab3[x][y][i]=0;
		tab3[x][i][z]=0;
		tab3[i][y][z]=0;
	}
	tab3[x][y][z]=1;
}

void inital3()
{
	memset(tab3,-1,sizeof(tab3));
	//tab2[0][0]=1;
	for(int i=0;i<303;i++)
	  for(int j=0;j<303;j++)
	    for(int k=0;k<303;k++)
		  {
		  	if(tab3[i][j][k]!=-1)continue;
		  	if(check3(i,j,k))
		  	{
		  		mark3(i,j,k);
		  		mark3(i,k,j);
		  		mark3(k,i,j);
		  		
		  		mark3(j,i,k);
		  		mark3(j,k,i);
		  		mark3(k,j,i);
		  	}
		  }
	/*
	for(int i=0;i<10;i++)
	{
	    cout<<i<<endl;
	  for(int k=0;k<10;k++)
	   {
		  for(int j=0;j<10;j++)
		    cout<<tab3[i][k][j]<<" ";
		  cout<<endl;
	   }
	   cout<<endl;
	}
	*/
}

int main()
{
	int n;
	int a[5];
	cin>>n;
	if(1==n)
	{
		cin>>a[0];
		if(a[0])cout<<"BitLGM"<<endl;
		else cout<<"BitAryo"<<endl;
	}
	else if(2==n)
	{
		inital2();
		cin>>a[0]>>a[1];
		//cout<<tab2[a[0]][a[1]]<<endl;
		if(tab2[a[0]][a[1]])cout<<"BitAryo"<<endl;
		else cout<<"BitLGM"<<endl;
	}
	else if(3==n)
	{
		inital3();
		cin>>a[0]>>a[1]>>a[2];
		if(tab3[a[0]][a[1]][a[2]])cout<<"BitAryo"<<endl;
		else cout<<"BitLGM"<<endl;
	}
	return 0;
}

Comments