Submission #636179

# Submission time Handle Problem Language Result Execution time Memory
636179 2022-08-28T13:10:38 Z slime Rarest Insects (IOI22_insects) C++17
100 / 100
60 ms 568 KB
#include "insects.h"
#include "bits/stdc++.h"
using namespace std;
 
set<int> machine;
 
int pvans; // Answer doesn't change if machine doesn't change
 
 
int inc = 0, outc = 0, qc = 0;
void move_in(int i) {
  if(machine.count(i)) return;
  machine.insert(i);
  move_inside(i);
  inc++;
  pvans = -1;
}
 
void move_out(int i) {
  if(machine.count(i)) {
    machine.erase(i);
    move_outside(i);
    outc++;
    pvans = -1;
  }
}
 
 
int query() {
  if(pvans == -1) {
    qc++;
    return pvans = press_button();
  }
  return pvans;
}
 
 
bool in_machine(int i) {
  return machine.count(i);
}
mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
 
int rnd(int x, int y) {
  return uniform_int_distribution<int>(x, y)(rng);
}
 
int min_cardinality(int N) {
  inc = 0, outc = 0, qc = 0;
  machine.clear();
  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);
  }
 */
  if(T == 1) return N;
  int lb = 1, rb = N/T;
  vector<int> relevant;
  for(int i=0; i<N; i++) relevant.push_back(i);
  int sub = 0;
  while(lb < rb) {
    int mid = (lb + rb + 1) >> 1;
    
    int good = 0;
    int m = relevant.size();

    shuffle(relevant.begin(), relevant.end(), rng);
 
    
    set<int> gv, bv;
    for(int x: relevant) {
      
      int qans;
      if(mid == sub || good == T * (mid - sub)) qans = 100000;
      else {
        move_in(x);
        qans = query();
      }
      if(qans > mid - sub) {
        move_out(x);
        bv.insert(x);
      }
      else {
        good++;
        gv.insert(x);
      }
    }
    if(good == T * (mid - sub)) {
      lb = mid;
      sub = mid;
      relevant.clear();
      for(int x: bv) relevant.push_back(x);
    }
    else {
      rb = mid - 1;
      relevant.clear();
      for(int x: gv) relevant.push_back(x);
    }
    if(lb < rb) {
      for(int i=0; i<N; i++) {
        move_out(i);
      }
    }
  }
  return lb;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:79:9: warning: unused variable 'm' [-Wunused-variable]
   79 |     int m = relevant.size();
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 6 ms 308 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 6 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 6 ms 308 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 6 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 312 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 11 ms 324 KB Output is correct
25 Correct 29 ms 324 KB Output is correct
26 Correct 21 ms 328 KB Output is correct
27 Correct 15 ms 332 KB Output is correct
28 Correct 10 ms 312 KB Output is correct
29 Correct 23 ms 348 KB Output is correct
30 Correct 30 ms 340 KB Output is correct
31 Correct 25 ms 320 KB Output is correct
32 Correct 26 ms 316 KB Output is correct
33 Correct 22 ms 344 KB Output is correct
34 Correct 23 ms 288 KB Output is correct
35 Correct 27 ms 296 KB Output is correct
36 Correct 27 ms 296 KB Output is correct
37 Correct 21 ms 304 KB Output is correct
38 Correct 20 ms 332 KB Output is correct
39 Correct 17 ms 308 KB Output is correct
40 Correct 13 ms 324 KB Output is correct
41 Correct 7 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 16 ms 208 KB Output is correct
8 Correct 15 ms 336 KB Output is correct
9 Correct 55 ms 416 KB Output is correct
10 Correct 51 ms 504 KB Output is correct
11 Correct 52 ms 452 KB Output is correct
12 Correct 30 ms 316 KB Output is correct
13 Correct 53 ms 412 KB Output is correct
14 Correct 44 ms 456 KB Output is correct
15 Correct 55 ms 412 KB Output is correct
16 Correct 38 ms 364 KB Output is correct
17 Correct 60 ms 420 KB Output is correct
18 Correct 48 ms 436 KB Output is correct
19 Correct 58 ms 412 KB Output is correct
20 Correct 46 ms 408 KB Output is correct
21 Correct 57 ms 428 KB Output is correct
22 Correct 59 ms 416 KB Output is correct
23 Correct 53 ms 332 KB Output is correct
24 Correct 49 ms 432 KB Output is correct
25 Correct 24 ms 408 KB Output is correct
26 Correct 16 ms 304 KB Output is correct
27 Correct 46 ms 448 KB Output is correct
28 Correct 40 ms 428 KB Output is correct
29 Correct 45 ms 424 KB Output is correct
30 Correct 46 ms 436 KB Output is correct
31 Correct 52 ms 428 KB Output is correct
32 Correct 51 ms 328 KB Output is correct
33 Correct 56 ms 412 KB Output is correct
34 Correct 51 ms 332 KB Output is correct
35 Correct 33 ms 412 KB Output is correct
36 Correct 54 ms 428 KB Output is correct
37 Correct 34 ms 400 KB Output is correct
38 Correct 45 ms 388 KB Output is correct
39 Correct 44 ms 428 KB Output is correct
40 Correct 55 ms 424 KB Output is correct
41 Correct 45 ms 568 KB Output is correct
42 Correct 49 ms 428 KB Output is correct
43 Correct 14 ms 208 KB Output is correct
44 Correct 36 ms 344 KB Output is correct
45 Correct 41 ms 424 KB Output is correct
46 Correct 27 ms 452 KB Output is correct
47 Correct 35 ms 328 KB Output is correct
48 Correct 35 ms 428 KB Output is correct