Submission #804071

#TimeUsernameProblemLanguageResultExecution timeMemory
804071thimote75Colors (BOI20_colors)C++14
100 / 100
7 ms364 KiB
#include <bits/stdc++.h>
#define int long long

using namespace std;

bool query (int Q) {
    cout << "? " << Q << endl;

    int x; cin >> x;
    return x == 1;
}
int gen_start (int N) {
    // suppose N = C
    int a = 0; // a < C <= b
    int b = N;

    int pos = 0;
    int mpos = 0;
    bool f = false;
    while (b - a > 1) {
        int c = (a + b) >> 1;
        
        a = c;
        if (f) pos -= c;
        else pos += c;

        mpos = min(mpos, pos);
        f = !f;
    }

    return mpos;
}

signed main () {
    int N;
    cin >> N;

    int mpos = - gen_start(N) + 1;
    query(mpos);

    int a = 0; // a < C <= b
    int b = N;

    bool delUp = true;
    int pos = mpos;
    while (b - a > 1) {
        int t = (a + b) >> 1;

        if (delUp) pos += t;
        else pos -= t;

        delUp = !delUp;

        if (query(pos)) b = t;
        else a = t;
    }

    cout << "= " << b << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...