Codeforces will be possibly unavailable in the period between Sep. 19, 19:00 (UTC) and Sep. 19, 21:00 (UTC) because of maintenance. ×

WA on gym103049-problem D

Revision en3, by AC_in_the_dark, 2021-05-07 03:29:05

D. Dragon Balls

It's an interactive problem. One code can pass, but the other one got "Wrong answer on test 14". I tried test 14 locally. It seems that it can give the right answer. Does anyone know what's wrong with it?

By the way, I don't know if I should use something like cout.flush() for interactive problems. It seems that some submissions passed without any cout.flush() or endl. (They simply use "\n" to type a new line.) So should I pay attention to flush my output in such cases?

//WA code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL x, y;
signed main()
{
    int T; cin >> T;
    while(T--)
    {
        cout << "0 0" << endl;
        LL d1; cin >> d1;
        if(!d1) continue;
        cout << "1 0" << endl;
        LL d2; cin >> d2;
        if(!d2) continue;
        if(d1 < d2)
        {
            x = 0; y = sqrt(d1);
            cout << x << " " << y << endl;
        }
        else
        {
            x = d1 - d2 + 1 >> 1; y = sqrt(d1- x*x);
            cout << x << " " << y << endl;
        }
        cin >> d1;
    }

	return 0;
}
//AC code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
signed main()
{
    int T; cin >> T;
    while(T--)
    {
        cout << "0 0" << endl;
        LL d1; cin >> d1;
        if(!d1) continue;
        cout << "1 0" << endl;
        LL d2; cin >> d2;
        if(!d2) continue;
        cout << "0 1" << endl;
        LL d3; cin >> d3;
        if(!d3) continue;
        LL x = d1 - d2 + 1 >> 1;
        cout << x << " " << (LL)sqrt(d1 - x*x) << endl;
        cin >> d2;
        if(!d2) continue;
        LL y = d1 - d3 + 1 >> 1;
        cout << (LL)sqrt(d1 - y*y) << " " << y << endl;
        cin >> d3;
    }

	return 0;
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English AC_in_the_dark 2021-05-07 03:29:05 1852 Change: the codes are pasted right here.
en2 English AC_in_the_dark 2021-05-06 11:24:36 0 (published)
en1 English AC_in_the_dark 2021-05-06 11:23:08 760 Initial revision (saved to drafts)