#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool did_archie_notice(ll col) {
int ans;
cout << "? " << col << endl;
cin >> ans;
cout.flush();
return (ans == 1);
}
int main() {
ll N;
cin >> N;
set<ll> used_up;
ll curren_hair_color = N/3ll + 1ll;
did_archie_notice(curren_hair_color);
ll maximum_possible_value_C = N;
ll minimum_possible_value_C = 1ll;
ll next_direc = 1ll;
while (maximum_possible_value_C!=minimum_possible_value_C) {
//cout << "max pv:" << maximum_possible_value_C << ",min pv:" << minimum_possible_value_C << " ,haircol:" << curren_hair_color << "\n";
ll to_check = (maximum_possible_value_C+minimum_possible_value_C)/2ll;
ll oldhaircolor = curren_hair_color;
bool hasnoticed = true;
for (ll chk_disp = 0; ; chk_disp++) {
ll next_check= curren_hair_color + next_direc*(to_check-chk_disp);
if ((to_check-chk_disp) >= maximum_possible_value_C || (to_check-chk_disp) < minimum_possible_value_C) {
throw exception();
}
if (used_up.count(next_check)==0) {
used_up.insert(next_check);
hasnoticed = did_archie_notice(next_check);
curren_hair_color = next_check;
break;
}
next_check= curren_hair_color + next_direc*(to_check+chk_disp);
if ((to_check+chk_disp) >= maximum_possible_value_C || (to_check+chk_disp) < minimum_possible_value_C) {
throw exception();
}
if (used_up.count(next_check)==0) {
used_up.insert(next_check);
hasnoticed = did_archie_notice(next_check);
curren_hair_color = next_check;
break;
}
}
if (hasnoticed) {
maximum_possible_value_C = abs(oldhaircolor-curren_hair_color);
}
else {
minimum_possible_value_C = abs(oldhaircolor-curren_hair_color)+1ll;
}
next_direc *= -1ll;
}
cout << "= " << maximum_possible_value_C << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |