Submission #649667

# Submission time Handle Problem Language Result Execution time Memory
649667 2022-10-11T08:10:26 Z welleyth Colors (BOI20_colors) C++17
0 / 100
1 ms 208 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define mp make_pair

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

constexpr int N = (int)2e5 + 111;
constexpr int md = (int)2e5 + 111;

mt19937 rnd(time(nullptr));

set<int> was_asked;

int pr = 1;
map<pair<int,int>,int> history;

int ask(int x){
    if(history.count(mp(x,pr)))
        return history[mp(x,pr)];
    assert(!was_asked.count(x));
    was_asked.insert(x);
    cout << "? " << x << "\n";
    cout.flush();
    int answer;
    cin >> answer;
    history[mp(pr,x)] = history[mp(x,pr)] = answer;
    return answer;
}

void solve(){
    int n;
    cin >> n;

    ask(1);

    int l = 2, r = n;
    vector<pair<int,int>> v;
    for(int it = 0; l <= r; it^=1){
        if(it == 0){
            v.pb(mp(l,r));
            r--;
//            int check = ask(r--);
//            if(!check){
//                cout << "= " << r - l + 3 << "\n";
//                return;
//            }
        } else {
            v.pb(mp(l,r));
            l++;
//            int check = ask(l++);
//            if(!check){
//                cout << "= " << r - l + 3 << "\n";
//                return;
//            }
        }
    }

    reverse(v.begin(),v.end());

    l = 0, r = n;
    while(r - l > 1){
        int m = (l+r)>>1;
//        cerr << "m = " << m << "\n";
        int a = v[m-1].first, b = v[m-1].second;
//        cerr << a << " " << b << "\n";
        if(rnd()&1) swap(a,b);
        if(history.count(mp(a,b))){
            int c = history[mp(a,b)];
            if(c == true)
                r = m;
            else
                l = m;
            continue;
        }
        if(was_asked.count(a) && was_asked.count(b))
            break;
        if(pr != a && pr != b){
            if(!was_asked.count(a)){
                pr = a;
                ask(a);
            } else if(!was_asked.count(b)){
                pr = b;
                ask(b);
            } else
                assert(false);
        }
        if(was_asked.count(a) && was_asked.count(b))
            break;
        int c;
        if(pr == a){
            c = ask(b);
        } else if(pr == b){
            c = ask(a);
        }
        if(c == true)
            r = m;
        else
            l = m;
    }

    int ans;
//    cerr << l << " " << r << "\n";
    ans = rnd()%(r - l)+l;

    cout << "= " << ans << "\n";

    return;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
//    init();
    int tests = 1;
//    cin >> tests;
    for(int test = 1; test <= tests; test++){
//        cerr << "test = " << test << "\n";
        solve();
    }
    return 0;
}
/**

**/

Compilation message

Colors.cpp: In function 'void solve()':
Colors.cpp:103:9: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
  103 |         if(c == true)
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB OK (5 queries)
2 Correct 1 ms 208 KB OK (11 queries)
3 Incorrect 0 ms 208 KB Wrong guess
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB OK (5 queries)
2 Correct 1 ms 208 KB OK (11 queries)
3 Incorrect 0 ms 208 KB Wrong guess
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB OK (5 queries)
2 Correct 1 ms 208 KB OK (11 queries)
3 Incorrect 0 ms 208 KB Wrong guess
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB OK (5 queries)
2 Correct 1 ms 208 KB OK (11 queries)
3 Incorrect 0 ms 208 KB Wrong guess
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB OK (5 queries)
2 Correct 1 ms 208 KB OK (11 queries)
3 Incorrect 0 ms 208 KB Wrong guess
4 Halted 0 ms 0 KB -