제출 #299570

#제출 시각아이디문제언어결과실행 시간메모리
299570E869120Colors (BOI20_colors)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; int Debug = 1; long long N; long long C = 21; long long prevs = 0; int getans(long long pos) { cout << "? " << pos << endl; if (Debug == 1) { int x; cin >> x; return x; } if (Debug == 2) { int x = -1; if (abs(prevs - pos) < C) x = 0; else x = 1; prevs = pos; return x; } return -1; } void solves() { // Step #1. Input cin >> N; if (N == 1) { cout << "= 1" << endl; return; } // Step #2. Get Answer long long cl = 1, cr = (N / 2) + 1, cm, minx = N; long long pre = -1; map<long long, int> Map; for (int i = 0; i < 100; i++) { cm = (cl + cr) / 2; if (Map[cm] == 1) break; Map[cm] = 1; int z1 = getans(cm); if (pre != -1LL && z1 == 1) minx = min(minx, abs(pre - cm)); pre = cm; int z2 = getans(N + 1LL - cm); if (pre != -1LL && z2 == 1) minx = min(minx, abs(pre - (N + 1LL - cm))); pre = N + 1LL - cm; if (z2 == 1) { cl = cm; } else { cr = cm; } } // Step #3. Baaiwake if (N % 2LL == 1LL) { int z3 = getans(N / 2LL + 1LL); if (pre != -1LL && z3 == 1) minx = min(minx, abs(pre - (N / 2LL + 1LL))); Map[N / 2LL + 1LL] = 1; } // Step #4. Baaiwake 2 if (minx >= 2LL) { long long target = minx - 1; for (int i = 1; i <= N - target; i++) { if (Map[i] == 0 && Map[i + target] == 0) { Map[i] = 1; Map[i + target] = 1; int z1 = getans(i); int z2 = getans(i + target); if (z2 == 1) minx = min(minx, target); break; } } } // Step #5. Get Answer cout << "= " << minx << endl; return; } int main() { solves(); }

컴파일 시 표준 에러 (stderr) 메시지

Colors.cpp: In function 'void solves()':
Colors.cpp:66:9: warning: unused variable 'z1' [-Wunused-variable]
   66 |     int z1 = getans(i);
      |         ^~
#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...