Problem link : CodeChef: Practical coding for everyone
I am getting partially correct answer with this code. Even one case with original constraints is passing. Please tell if you can spot the error.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int r = 100l,l=0,sq_side;
ll area;
sq_side = (l+r)/2;
while(sq_side>l)
{
string s;
cout<<"? "<<sq_side<<" 0"<<endl<<flush;
cin >> s;
if(s == "YES")
l = sq_side;
else
r = sq_side;
sq_side = (l+r)/2;
}
area = 4*sq_side*sq_side;
int y = 2 * sq_side, tri_base;
r = 1001; l = sq_side;
tri_base = (l+r)/2;
while(tri_base>l)
{
string s;
cout<<"? "<<tri_base<<" "<<y<<endl<<flush;
cin >> s;
if(s == "YES")
l = tri_base;
else
r = tri_base;
tri_base = (l+r)/2;
}
l = y, r = 1001;
int tri_height;
tri_height = (l+r)/2;
while(tri_height>l)
{
string s;
cout<<"? 0 "<<tri_height<<endl<<flush;
cin >> s;
if(s == "YES")
l = tri_height;
else
r = tri_height;
tri_height = (l+r)/2;
}
area += tri_base * (tri_height - y);
cout<<"! "<<area<<endl<<flush;
return 0;
}