forked from bhavyahoda/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryS.cpp
More file actions
120 lines (117 loc) · 2.11 KB
/
binaryS.cpp
File metadata and controls
120 lines (117 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// || || |____| //
// || || || //
// \\__// || //
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define mp make_pair
#define F first
#define S second
#define vll vector <ll>
#define mll map <ll,ll>
#define pb push_back
#define pf push_front
#define ub upper_bound
#define lb lower_bound
#define popf pop_front
#define popb pop_back
#define M 1000000007
#define M1 998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>(t);while(t--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f(a, b) for (ll i = a; i < b; i++)
#define fr(a, b) for (ll j = a; j >= b; j--)
#define fi(a, b) for (ll j = a; j < b; j++)
#define fii(a, b) for (ll k = a; k < b; k++)
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))
using namespace std;
void start()
{
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/***********************************************************************************************************/
ll check(ll x,ll y)
{
cout<<"? "<<x<<" "<<y<<endl;
fflush(stdout);
string s; cin>>s;
if(s[0]=='Y')
return 1;
return 0;
}
ll solve1(ll h)
{
ll l=0;
ll ans=-1,c;
while(l<=h)
{
ll m = (l+h)/2;
ans=check(0,m);
if(ans==1)
{
l=m+1;
c=m;
}
else
h=m-1;
}
return c;
}
ll solve2(ll h)
{
ll l=0;
ll ans=-1,c;
while(l<=h)
{
ll m = (l+h)/2;
ans = check(m,0);
if(ans==1)
{
l=m+1;
c=m;
}
else
h=m-1;
}
return c;
}
ll solve3(ll h,ll k)
{
ll l=k/2;
ll ans=-1,c;
while(l<=h)
{
ll m = (l+h)/2;
ans=check(m,k);
if(ans==1)
{
l=m+1;
c=m;
}
else
h=m-1;
}
return c;
}
int main()
{
start();
ll x = 1000, y = 1000;
ll x1,x2,x3;
x1 = solve1(y);
x2 = solve2(x);
x2*=2;
ll k = x1-x2;
x3 = solve3(x,x2);
ll ans= (x2*x2+x3*k);
cout<<"! "<<ans<<endl;
fflush(stdout);
return 0;
}