runtime error (SIGSEGV) in infinite grid game

for this question http://www.codechef.com/problems/IGAME , i am getting runtime error(SIGSEGV) with this solution CodeChef: Practical coding for everyone . but there are many successful submissions in C for this problem which also uses same amount of memory as i did that is 2-d array of around 1000*1000, like this CodeChef: Practical coding for everyone. what is the problem with my solution ?

This seems to me as the problem

while(x<=1000 || y<=1000) // Problem lies here

{

a[x][y]=‘0’;

a[y][x]=‘0’;

x=x+i+1;

y=y+i;

i++;

}

If either of x or y become > 1001 then you’ll access element which has not been allocated as your char array has dimensions 1002 * 1002, it should be “&&” instead of “||”. Hence the Runtime Error.

Regards,

Ouditchya Sinha.

1 Like

can you tell me why i am getting wrong answer with this solution CodeChef: Practical coding for everyone for the above question?

@seekay: I think your logic is wrong. I have printed your array here - LVkXtl - Online C Compiler & Debugging Tool - Ideone.com. Try to think of small test cases, you’ll realise your mistake.
All the Best. :slight_smile:

The link appears to be broken, just try printing your “a” array & cross check for small cases with pen & paper.

This is the link : LVkXtl - Online C Compiler & Debugging Tool - Ideone.com