Zarg's blog

By Zarg, 11 years ago, In English

http://www.spoj.com/problems/MATGAME/

I have been trying to solve this problem on spoj. I calculated grundy number for every row and than took their xor. I am getting wrong answer but am unable to find an error.

int ex = 0;
for(int i = 0; i < n; i ++)
{
    int g = ar[i][m-1];
    for(int j = m-2; j >= 0; j --)
    {
    if(g == 0)
        g = ar[i][j];
    else
        g = ar[i][j] - 1;
    }
    ex = ex ^ g;
}
if(ex) printf("FIRST\n");
else   printf("SECOND\n");

This is the code. Any help is greatly appreciated.

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it