이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
bool verdict;
// if (n <= 6){
// cout << "? 1" << endl;
// cin >> verdict;
// int i = 2;
// int j = n;
// int turn = 1;
// int ans = n;
// while (i <= j){
// if (turn){
// cout << "? " << j << endl;
// j--;
// turn = 0;
// }
// else{
// cout << "? " << i << endl;
// i++;
// turn = 1;
// }
// cin >> verdict;
// if (verdict == 0)
// break;
// ans--;
// }
// cout << "= " << ans << endl;
// return 0;
// }
if (n == 1){
cout << "= 1" << endl;
return 0;
}
int l = n / 4 + 1;
int r = n - l + 1;
cout << "? " << l << endl;
cin >> verdict;
cout << "? " << r << endl;
cin >> verdict;
if (verdict == 1){
int ans = r - l;
int turn = 1;
while (l + 1 < r){
if (turn){
l++;
cout << "? " << l << endl;
cin >> verdict;
turn = 0;
}
else{
r--;
cout << "? " << r << endl;
cin >> verdict;
turn = 1;
}
if (verdict == 0)
break;
ans--;
}
cout << "= " << ans << endl;
}
else{
int ans = r - l;
int turn = 1;
while (l - turn > 0 and r + 1 - turn <= n){
if (turn){
l--;
cout << "? " << l << endl;
cin >> verdict;
turn = 0;
}
else{
r++;
cout << "? " << r << endl;
cin >> verdict;
turn = 1;
}
if (verdict) break;
ans++;
}
cout << "= " << ans + 1 << endl;
}
}
# | 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... |