Submission #1078325

#TimeUsernameProblemLanguageResultExecution timeMemory
1078325Faisal_SaqibRarest Insects (IOI22_insects)C++17
100 / 100
504 ms16216 KiB
#include <bits/stdc++.h> using namespace std; void move_inside(int i); void move_outside(int i); int press_button(); mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); #define all(x) begin(x),end(x) #define SHUFFLE(v) shuffle(all(v), RNG); set<int> machine,rem,real_; void add(int x) { if(machine.find(x)==machine.end()) { machine.insert(x); } } void remp(int x) { if(machine.find(x)!=machine.end()) { machine.erase(x); } } map<vector<int>,int> store; int ask() { vector<int> cur(begin(machine),end(machine)); if(store.find(cur)!=store.end()) return store[cur]; for(auto&i:real_) if(machine.find(i)==machine.end()) move_outside(i); for(auto&i:machine) if(real_.find(i)==real_.end()) move_inside(i); real_=machine; return store[cur]=press_button(); } int min_cardinality(int n) { for(int i=0;i<n;i++){rem.insert(i);} { vector<int> order(begin(rem),end(rem)); add(order[0]); for(int i=1;i<n;i++) { add(order[i]); if(ask()>1) { remp(order[i]); } } } int sz=machine.size(); int s=1; int e=(n/sz)+1; while(s+1<e) { int mid=(s+e)/2; vector<int> cur; vector<int> order(begin(rem),end(rem)); SHUFFLE(order); for(auto&i:order) { if(machine.size()==(sz*mid)) break; add(i); if(machine.size()>mid and ask()>mid) { remp(i); } else { cur.push_back(i); if(machine.size()==(sz*mid)) break; } } if(machine.size()==((sz*mid))) { s=mid; for(auto&i:cur) rem.erase(i); } else{ int szp=machine.size(); e=min(mid,1+(szp/sz)); rem.clear(); for(auto&i:cur) { rem.insert(i); remp(i); } } } return s; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:66:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |    if(machine.size()==(sz*mid))
      |       ~~~~~~~~~~~~~~^~~~~~~~~~
insects.cpp:69:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |    if(machine.size()>mid and ask()>mid)
      |       ~~~~~~~~~~~~~~^~~~
insects.cpp:76:22: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |     if(machine.size()==(sz*mid))
      |        ~~~~~~~~~~~~~~^~~~~~~~~~
insects.cpp:80:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |   if(machine.size()==((sz*mid)))
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...