why do i get wrong answer for stone game: CodeChef: Practical coding for everyone
@hanisha: ur program fails for the following case:
Testcase:
1
5
1 2 1 2 1
ur program outputs ALICE but result should be BOB, because
- in 1st turn consider alice removes the stones at 1st position. the array will become 0 2 1 2 1.
- in bob’s turn if bob removes the stones at 2nd position, the array is 0 0 1 2 1.
- in the next turn since there are no stones such that a[i]>=i, ALICE loses, BOB wins being the last to have removed the stones.
the reason for WA is that ur program stops as soon as it encounters the first i such that a[i]>=i, but the program asks to calculate the total i where a[i]>=i.
link to the WA solution.
link to corrected solution.
if there are even number of a[i]>=i BOB wins,else ALICE wins.