제출 #831324

#제출 시각아이디문제언어결과실행 시간메모리
831324definitelynotmee드문 곤충 (IOI22_insects)C++17
90.09 / 100
89 ms504 KiB
// Second submission after reading edi #include "insects.h" #include<bits/stdc++.h> #define all(x) x.begin(), x.end() using ll = long long; using namespace std; template<typename T> using matrix = vector<vector<T>>; struct Machine { set<int> s; void insert(int id){ s.insert(id); move_inside(id); } void erase(int id){ s.erase(id); move_outside(id); } int resp(){ return press_button(); } void clear(){ auto it = s.begin(); while(it!=s.end()){ move_outside(*it); it = s.erase(it); } } }; int min_cardinality(int N) { mt19937 rng(time(nullptr)); vector<int> dif; vector<int> resto; Machine m; for(int i = 0; i < N; i++){ m.insert(i); if(m.resp() == 1){ dif.push_back(i); } else m.erase(i), resto.push_back(i); } shuffle(all(dif),rng); shuffle(all(resto),rng); m.clear(); int ini = 1, fim = N/dif.size(); auto putless =[&](int mx){ for(int i : resto){ if(m.s.count(i)) continue; m.insert(i); if(m.resp() > mx) m.erase(i); } }; int last = -1; while(ini!=fim){ int mid = (ini+fim+1)>>1; // cerr << "mid = " << mid << '\n'; if(mid < last){ vector<int> newresto; for(int i : m.s) newresto.push_back(i); swap(resto,newresto); m.clear(); } putless(mid-1); bool ok = 1; for(int i : dif){ m.insert(i); ok&= m.resp() == mid; m.erase(i); } if(ok) ini = mid; else fim = mid-1; last = mid; } return ini; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...