# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
614153 | cadmiumsky | Colors (BOI20_colors) | C++14 | 1 ms | 208 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int last;
bool query(int x) {
cout << "? " << x + 1 << endl;
last = x;
cin >> x;
return x;
}
signed main() {
int n;
cin >> n;
n--;
vector<int> bits;
int msk = 0;
for(int i = 60; i >= 0; i--) {
if((1LL << i) & n)
bits.push_back(i),
(bits.size() % 2 == 0? msk |= (1LL << i): 0);
}
for(auto x : bits)
cerr << x << ' ';
cerr << '\n';
int mine = 0, lelim = -1, toggle = 0;
query(msk);
for(int i = 0, x; i < bits.size(); i++) {
x = bits[i];
if(toggle) {
if(!query(last - mine - (1 << x)))
last -= (1LL << x);
else
break;
}
else {
if(!query((1LL << x) + mine + last))
mine += (1LL << x);
else
break;
}
lelim = i;
toggle ^= 1;
}
lelim++;
assert(lelim != bits.size());
lelim = bits[lelim] - 1;
if(lelim >= 0) {
query((1LL << lelim));
toggle = 0;
for(int i = lelim; i >= 0; i--) {
if(toggle == 0) {
if(!query(last + (1LL << i) + mine))
mine += (1LL << i);
}
else {
if(!query(last - mine - (1LL << i)))
mine += (1LL << i);
}
toggle ^= 1;
}
}
cout << "! " << mine + 1 << endl;
}
// n = 24, C = 19
Compilation message (stderr)
# | 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... |