Submission #446073

#TimeUsernameProblemLanguageResultExecution timeMemory
446073OzyColors (BOI20_colors)C++17
100 / 100
3 ms328 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define lli long long int #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " lli n,ini,fin,start,mitad,n2,res,dir; stack<lli> pila; bool query(lli a) { cout << "? " << a << endl; cin >> a; if (a == 1) return true; else return false; } int main() { ios_base::sync_with_stdio(false); cin >> n; ini = 1; fin = n-1; start = n; n2 = n/2; while (ini <= fin) { mitad = (ini+fin)/2; pila.push(mitad); ini = mitad+1; } while(!pila.empty()) { if (start > n2) start -= pila.top(); else start += pila.top(); pila.pop(); } bool x = query(start); ini = 1; fin = n-1; res = 0; if (start > n2) dir = -1; else dir = 1; while (ini <= fin) { mitad = (ini+fin)/2; start += mitad*dir; dir *= -1; if (query(start)) fin = mitad - 1; else { res = mitad; ini = mitad+1; } } cout << "= " << res+1; }

Compilation message (stderr)

Colors.cpp: In function 'int main()':
Colors.cpp:43:10: warning: unused variable 'x' [-Wunused-variable]
   43 |     bool x = query(start);
      |          ^
#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...