#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
int c;
void init(int n){
cin>>c;
}
int last;
bool query(int x){
cout<<"? "<<x<<' ';
if(abs(x-last)>=c){
last=x;
cout<<1<<'\n';
return 1;
}
last=x;
cout<<0<<'\n';
return 0;
}
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void init(int n){}
bool query(int x){
cout<<"? "<<x<<endl;
cin>>x;
return x;
}
void setio(){}
#define debug(x...)
#endif
signed main(){
setio();
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin>>n;
init(n);
int x=query(1);
int l=1,r=n;
int prev=1;
while(l<r){
int mm=l+r>>1;
if(prev-mm<1 or (prev+mm<=n and n-prev-mm<prev-mm-1)){
x=query(prev+mm);
prev=prev+mm;
}
else if(prev-mm>=1){
x=query(prev-mm);
prev=prev-mm;
}
else{
x=query(1);
prev=1;continue;
}
if(x){
r=mm;
}
else{
l=mm+1;
}
}
cout<<"= "<<l<<'\n';
}
/*
input:
*/
Compilation message
Colors.cpp: In function 'int main()':
Colors.cpp:75:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
75 | int mm=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
704 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
704 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
704 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
704 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
704 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |