Submission #1057967

#TimeUsernameProblemLanguageResultExecution timeMemory
1057967Dan4LifeRarest Insects (IOI22_insects)C++17
25 / 100
2346 ms218872 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; bool move_in(int i){ if(S.count(i)) return 0; S.insert(i); move_inside(i); return 1; } bool move_out(int i){ if(!S.count(i)) return 0; S.erase(i); move_outside(i); return 1; } 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--; } for(int i = 0; i < n; i++) move_out(xd[i]); int l = 1, r = n; while(l<r){ int mid = (l+r+1)/2, tot=n; vi undo; undo.clear(); for(int i = 0; i < n; i++){ if(!move_in(xd[i])) continue; if(press()>mid) move_out(xd[i]), tot--; else undo.pb(xd[i]); } if(tot==D*mid) l = mid; else{ for(auto u : undo) move_out(u); r=mid-1; } } return l; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:36:13: warning: unused variable 'ans' [-Wunused-variable]
   36 |  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...