Submission #1057958

#TimeUsernameProblemLanguageResultExecution timeMemory
1057958Dan4LifeRarest Insects (IOI22_insects)C++17
25 / 100
2249 ms218948 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a), end(a) using vi = vector<int>; using ll = long long; using ar2 = array<ll,2>; using ar3 = array<ll,3>; const int mxN = (int)2e3+10; int n, cnt[mxN]; vi v, others; set<int> S; map<set<int>,int> M; void move_in(int i){ if(S.count(i)) return; S.insert(i); move_inside(i); } void move_out(int i){ if(!S.count(i)) return; S.erase(i); move_outside(i); } int press(){ if(sz(S)==1) return 1; if(M.count(S)) return M[S]; return M[S] = press_button(); } int min_cardinality(int N) { n = N; int ans = n, D=n; vector<int> xd(n,0); iota(all(xd),0); random_shuffle(all(xd)); for(int i = 0; i < n; i++){ move_in(xd[i]); if(press()==2) move_out(xd[i]), D--; } int l = 1, r = n; while(l<r){ int mid = (l+r+1)/2, tot=0; for(int i = 0; i < n; i++) move_out(xd[i]); for(int i = 0; i < n; i++){ move_in(xd[i]); tot++; if(press()>mid) move_out(xd[i]), tot--; } if(tot==D*mid) l=mid; else r=mid-1; } return l; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:34:13: warning: unused variable 'ans' [-Wunused-variable]
   34 |  n = N; int ans = n, D=n;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...