Submission #804559

# Submission time Handle Problem Language Result Execution time Memory
804559 2023-08-03T09:48:52 Z rnl42 Colors (BOI20_colors) C++14
0 / 100
300 ms 208 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N;

inline int getvalid(int N) {
    int mincur = 0, maxcur = 0;
    int cur = 0;
    int mini = 1, maxi = N-1;
    bool parity = false;
    while (mini <= maxi) {
        int mid = (mini+maxi)>>1;
        int next;
        if (!parity) {
            next = cur+mid;
        } else {
            next = cur-mid;
        }
        mini = mid+1;
        cur = next;
        parity ^= 1;
        mincur = min(mincur, cur);
        maxcur = max(maxcur, cur);
    }
    return -mincur;
}

inline bool query(int x) {
    cout << "? " << x+1 << '\n' << flush;
    bool ret;
    cin >> ret;
    return ret;
}

signed main() {
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> N;
    int cur = getvalid(N);
    int mini = 1, maxi = N-1;
    query(cur);
    bool parity = false;
    while (mini < maxi) {
        int mid = (mini+maxi+1)>>1;
        int next;
        if (!parity) {
            next = cur+mid;
        } else {
            next = cur-mid;
        }
        if (query(next)) {
            maxi = mid;
        } else {
            mini = mid+1;
        }
        parity ^= 1;
        cur = next;
    }
    cout << "= " << mini << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB OK (3 queries)
2 Execution timed out 2388 ms 208 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB OK (3 queries)
2 Execution timed out 2388 ms 208 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB OK (3 queries)
2 Execution timed out 2388 ms 208 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB OK (3 queries)
2 Execution timed out 2388 ms 208 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB OK (3 queries)
2 Execution timed out 2388 ms 208 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -