# Help with QHOUSE

This is my code here. I am getting Partially Correct answer. The link to the problem : CodeChef: Practical coding for everyone

``````#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define int long long
#define MOD 1000000007
#define w(x) int x; cin >> x; while(x--)
#define	F first
#define S second
#define PB push_back

string s;

cout << "? " << x << " " << y << endl;
cin >> s;
return (s == "YES");

}

void solve(){

int x = -1;

//Finding the side of square
for(int b = 1000; b >= 1; b/=2)
{
while(ask(x + b, 0)) x += b;

}

int sq = 2*x;

//Finding the height of the figure
int y = -1;
for(int b = 1000; b >= 1; b/=2)
{
while(ask(0, y + b)) y += b;

}
//Height of triangle
int h = y - sq;

// Finding the base of the triangle
int tx = -1;
for(int b = 1000; b >= 1; b/=2)
{
while(ask(tx + b, sq)) tx += b;

}

cout << "! " << sq*sq + h*tx << endl;

}

int32_t main(){

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int t = 1;
//cin >> t;
while(t--)
solve();

return 0;

}
``````

`

Thank you for your advice. I have done the formatting and provided the link of the problem

You are missing the main function and the header files. I need to copy your code and run it to see what’s wrong. Please post the entire code.

I have posted the entire code.

Your binary search may go out of the valid range. On your query function you should check for that and return false yourself.

1 Like

Thank you for looking into code. I tried to think of multiple test cases that might take the range 1000 but it didn’t go. I have specified the upper bound to be 1000 in the binary search so I don’t think it will ever go above that

``````//b will start from 1000 so it will never go above 1000.
for(int b = 1000; b >= 1; b/=2)
{
while(ask(x + b, 0)) x += b;

}
``````

What if 999,0 was inside the square? You would ask 999+1000,0, which is out of the valid query range.
https://www.codechef.com/viewsolution/33112326