Submission #628924

#TimeUsernameProblemLanguageResultExecution timeMemory
628924dqhungdlRarest Insects (IOI22_insects)C++17
57.13 / 100
162 ms328 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; int diff = 0; vector<bool> mark; void countDiff(int N) { for (int i = 0; i < N; i++) { move_inside(i); if (press_button() == 1) { diff++; mark[i] = true; } else move_outside(i); } } bool check(int lim, int N) { if (press_button() > lim) { for (int i = 0; i < N; i++) if (mark[i]) { mark[i] = false; move_outside(i); } } int cnt = accumulate(mark.begin(), mark.end(), 0); for (int i = 0; i < N; i++) if (!mark[i]) { move_inside(i); if (press_button() > lim) move_outside(i); else { cnt++; mark[i] = true; } } return cnt < lim * diff; } int min_cardinality(int N) { mark.resize(N); countDiff(N); if (diff == N) return 1; int LIM = N / diff, step = max(LIM / 5, 1); int l, r, rs = 1; for (int i = step + 1; i <= LIM; i += step) { if (check(i, N)) { l = i - step + 1, r = i - 1; break; } rs = i; if (i + step > LIM) l = i + 1, r = LIM; } while (l <= r) { int mid = (l + r) / 2; if (check(mid, N)) r = mid - 1; else { rs = mid; l = mid + 1; } } return rs; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:58:22: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |         int mid = (l + r) / 2;
      |                   ~~~^~~~
insects.cpp:58:22: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...