이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N = 5e5+10;
const int INF = 2e18;
int cnt = 0;
int n;
set<int> ss;
int ask(int p){
if (ss.find(p)!=ss.end()){
cerr << p << "被用過了\n";
assert(0);
}
ss.insert(p);
if (cnt==64){
cout << "問太多次了\n";
assert(0);
}
cnt++;
cout << "? " << p << endl;
int res;
cin >> res;
return res;
}
void answer(int p){
cout << "= " << p << endl;
exit(0);
return;
}
void solve2(){
int ll = 1, rr = n;
while (ll<=rr){
if (ask(ll)==0 && ll!=1){
answer(rr-ll+2);
}
ll++;
if (!(ll<=rr)){
break;
}
if (ask(rr)==0){
answer(rr-ll+2);
}
rr--;
}
answer(1);
return;
}
void solve1(){
// input
cin >> n;
// process
if (n<=64){
solve2();
}
int ll = 1, rr = n+1, ans = rr;
int now = 1;
while (ll<rr){
int mid = (ll+rr)/2;
int xx = 1;
int yy = 1;
ask(xx);
int res = ask(yy);
if (res==1){
ans = mid;
rr = mid;
}else{
ll = mid+1;
}
now++;
}
answer(ans);
return;
}
signed main(){
int t = 1;
while (t--){
solve1();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |