Submission #804039

#TimeUsernameProblemLanguageResultExecution timeMemory
804039thimote75Colors (BOI20_colors)C++14
67 / 100
1 ms256 KiB
#include <bits/stdc++.h> 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; } int 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...