Bug in RUNDIR of april cookoff 2018

Can anyone tell me what’s the reason behind this problem.

I have two solution of this RUNDIR problem of april 2018 cookoff div1.

Both the solutions are same , its just that in one solution i am printing -1 as :


and in another by :

double temp = -1;


but the problem is that first approach gives wrong answer but second coorect.

Here are the links:

Approach 1 : https://www.codechef.com/viewsolution/18341188

Approach 2 : https://www.codechef.com/viewsolution/18341948


Have a look at this: std::ios_base::sync_with_stdio - cppreference.com

Because you are un-syncing the two output streams by having the line “ios_base::sync_with_stdio(false);” in your code, and because you are having both printf and cout statements, the output becomes interleaved (see the example in that linked page).
If you just comment out the sync_with_stdio statement, your code gets AC-ed.



Forwarded to @admin for review.

thanks for letting me know my mistake :slight_smile: