Different Answers

I ran the code given below on Ideone and on Xcode (an IDE on mac). Shockingly, they gave me two different answers for the test cases given along with the problem.

Ideone shows “Nana”. Whereas Xcode shows “Nobody wins”.

Ideone:
alt text

Xcode:
alt text

Ideone is showing an incorrect answer. Codechef is giving a WA too. What can the reason be for this discrepancy?

My code: http://ideone.com/QWFdC7
EDIT: Latest code - http://ideone.com/BBNQKi

Problem: http://www.codechef.com/problems/NUMBERS/

@dhruvmullick i executed your code in my Linux machine and it showed the same output as given in the test case…so i’think there is some other problem in your code …

4 Likes

On a quick look I found these issues in your code:

Line 41: sort(player,0,n,temp); - I believe it should be sort(player,0,n-1,temp); instead.

Line 134: sort(player, imid, iend, temp); - Element at imid position has already been sorted in line 133. Why sort it again? It should be sort(player, imid+1, iend, temp); instead.

The discrepancy you are talking about is most probably due to processing of garbage values I pointed out above. In addition to it, your algorithm will give unexpected results if you execute it for N=1 case. I will leave it to you to figure out why.

An advice - declare your bigger arrays global or there is a great chance that you will get TLE. Again, I will leave it to you to figure out why :slight_smile:

3 Likes

@raj01104 Okay but that still doesn’t explain the different outputs. I’ve had another weird result when I try to print the inputs after sorting.
Ideone shows the correct result, but my IDE shows something else

Correct : http://ideone.com/BBNQKi
Incorrect http://imgur.com/v4OvOkT

Okay, I am getting some really unexpected results when N= 1. I’ll have to correct this. Thanks for help!