Submission #557102

#TimeUsernameProblemLanguageResultExecution timeMemory
557102aryan12Colors (BOI20_colors)C++17
0 / 100
1 ms316 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); void Solve() { int n; cin >> n; if(n == 2) { cout << "? 1" << endl; int reply; cin >> reply; cout << "? 2" << endl; cin >> reply; reply = 1 - reply; cout << "= " << reply + 1 << endl; return; } int reply; cout << "? " << 3 * n / 4 << endl; cin >> reply; cout << "? " << n / 4 << endl; cin >> reply; set<int> already_replied; already_replied.insert(3 * n / 4); already_replied.insert(n / 4); int value = (3 * n / 4) - (n / 4); int to_check = value; if(reply == 0) { to_check += value / 2; } else { to_check -= value / 2; } // cout << "value = " << value << ", to_check = " << to_check << endl; int queries = 2; int current_value = n / 4; int final_answer = (reply == 0) ? n : (3 * n / 4 - n / 4); while(true) { queries++; if(queries == 65) { break; } // cout << "current to check is: " << to_check << endl; int to_the_left = current_value - to_check; int to_the_right = current_value + to_check; if(already_replied.count(to_the_left) || to_the_left <= 0) { if(already_replied.count(to_the_right) || to_the_right > n) { for(int i = 1; i <= n; i++) { if(!already_replied.count(i)) { cout << "? " << i << endl; cin >> reply; current_value = i; already_replied.insert(i); break; } } } else { cout << "? " << to_the_right << endl; already_replied.insert(to_the_right); cin >> reply; value /= 2; current_value = to_the_right; if(reply == 0) { to_check += value / 2; } else { final_answer = to_check; to_check -= value / 2; } } } else { cout << "? " << to_the_left << endl; already_replied.insert(to_the_left); cin >> reply; value /= 2; current_value = to_the_left; if(reply == 0) { to_check += value / 2; } else { final_answer = to_check; to_check -= value / 2; } } } cout << "= " << final_answer << endl; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }
#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...