Submission #636106

#TimeUsernameProblemLanguageResultExecution timeMemory
636106slimeRarest Insects (IOI22_insects)C++17
0 / 100
55 ms460 KiB
#include "insects.h" #include "bits/stdc++.h" using namespace std; set<int> machine; int pvans; // Answer doesn't change if machine doesn't change void move_in(int i) { if(machine.count(i)) return; machine.insert(i); move_inside(i); pvans = -1; } void move_out(int i) { if(machine.count(i)) { machine.erase(i); move_outside(i); pvans = -1; } } int query() { if(pvans == -1) { return pvans = press_button(); } return pvans; } bool in_machine(int i) { return machine.count(i); } int min_cardinality(int N) { int T = 0; pvans = -1; for(int i=0; i<N; i++) { move_in(i); int pb = query(); if(pb == 1) { T++; } else { move_out(i); } } for(int i=0; i<N; i++) { move_out(i); } int lb = 1, rb = N/T; set<int> relevant; for(int i=0; i<N; i++) relevant.insert(i); while(lb < rb) { int mid = (lb + rb + 1) >> 1; int m = relevant.size(); int overflow = 0; for(int x: relevant) { move_in(x); int qans = query(); if(qans > mid) { move_out(x); overflow++; } } //cout << mid << " " << m << " " << T << " " << overflow << "\n"; if(overflow == N - T * mid) { lb = mid; } else { rb = mid - 1; relevant.clear(); for(int i=0; i<N; i++) { if(in_machine(i)) relevant.insert(i); } } } return lb; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:60:9: warning: unused variable 'm' [-Wunused-variable]
   60 |     int m = relevant.size();
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...