Submission #417119

#TimeUsernameProblemLanguageResultExecution timeMemory
417119aryan12Colors (BOI20_colors)C++17
67 / 100
2 ms304 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n, ans; int last; map<int, int> used; int get(int p) { used[p] = 1; cout << "? " << p << endl; int res; cin >> res; if(last && res && abs(last - p) < ans) { ans = abs(last - p); } last = p; return res; } int f(int x) { int i = n - x; return 1 + i / 2; } void Solve() { cin >> n; ans = n; int l = 1, r = n / 2 - (n % 2 == 0); while(l <= r) { int mid = (l + r) / 2; int a = f(mid + mid), b = f(mid + mid) + mid + mid; get(a); if(get(b)) { ans = min(mid + mid + 1, ans); r = mid - 1; } else { l = mid + 1; } } used[last] = 0; for(int i = 1; i + ans - 1 <= n && ans % 2 == 0 && ans > 1; i++) { if(!used[i] && !used[i + ans - 1]) { used[last] = 1; int a = i, b = i + ans - 1; if(b == last) { swap(a, b); } if(a != last) { get(a); } get(b); break; } } cout << "= " << ans << endl; } // int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); Solve(); 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...