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 :

cout<<"-1\n";

and in another by :

double temp = -1;

printf("%0.6lf\n",temp);

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

Forwarded to @admin for review.

Hey,

Have a look at this: http://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio

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.

Cheers,
CodeChef

3 Likes

thanks for letting me know my mistake :slight_smile: