# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
669740 | mychecksedad | Colors (BOI20_colors) | C++17 | 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.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD1 (1000000000+7)
#define MOD (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
bool ask(int c){
cout << "? " << c << endl;
bool r; cin >> r;
return r;
}
void result(int k){
cout << "= " << k << endl;
exit(0);
}
int n;
void solve(){
cin >> n;
vector<int> v;
int l = 1, r = n;
while(l <= r){
v.pb(l);
if(l != r)
v.pb(r);
if(l + 2 < r - 2)
l+=2, r-=2;
else
l++, r--;
}
vector<bool> used(n+1);
ask(v[0]);
used[v[0]] = 1;
for(int i = 1; i < v.size(); ++i){
bool b = ask(v[i]);
used[v[i]] = 1;
if(b == 0){
int d = abs(v[i] - v[i - 1]) + 1;
if(i > 1 && abs(v[i - 1] - v[i - 2]) == d) result(d);
if(d == n){
result(d);
}
if(v[i] - d >= 1 && !used[v[i] - d]){
b = ask(v[i] - d);
}else if(v[i] + d <= n && !used[v[i] + d]){
b = ask(v[i] + d);
}else{
for(int i = 1; i + d <= n; ++i){
if(!used[i] && !used[i + d]){
ask(i);
b = ask(i+d);
break;
}
}
}
if(b == 1){
result(d);
}else{
result(d + 1);
}
}
}
result(1);
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
}
return 0;
}
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... |