Submission #630567

# Submission time Handle Problem Language Result Execution time Memory
630567 2022-08-16T14:58:05 Z CyanForces Rarest Insects (IOI22_insects) C++17
100 / 100
70 ms 888 KB
#include "insects.h"

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define debug(...) //ignore
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;


int min_cardinality(int N) {
  int ADD = 0, REM = 0, QUE = 0;

  int n = N;
  set<int> active;
  set<int> dead;
  set<int> basis;
  using H = unsigned long long;
  vector<H> rnd(n);
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  rep(i,0,n) rnd[i] = rng();
  H hsh = 13;
  map<H,int> queried;
  queried[hsh] = 0;

  vi perm(n);
  iota(all(perm),0);
  shuffle(all(perm),rng);

  auto add = [&](int x) {
    assert(!active.count(x));
    assert(!dead.count(x));
    active.emplace(x);
    hsh ^= rnd[x];
    move_inside(perm[x]);
    ++ADD;
  };

  auto rem = [&](int x) {
    assert(active.count(x));
    assert(!dead.count(x));
    active.erase(x);
    hsh ^= rnd[x];
    move_outside(perm[x]);
    ++REM;
  };

  auto query = [&]() {
    if(!queried.count(hsh)) {
      queried[hsh] = press_button();
      ++QUE;
    }
    return queried[hsh];
  };

  auto empty_all = [&]() {
    rep(i,0,n) if(!dead.count(i) && active.count(i)) rem(i);
  };

  int distinct = -1;
  auto go = [&](int b) {
    rep(i,0,n) if(!active.count(i) && !dead.count(i)) {
      add(i);
      if(query() > b) rem(i);
      if(sz(active) == b*distinct) return;
    }
  };

  go(1);
  distinct = sz(active);

  int l = 1, r = n/distinct+1;
  if(distinct == 1) l = n;
  while(l+1 != r) {
    int m = (l+r)/2;
    go(m);
    if(sz(active) == m * distinct) {
      l = m;
      for(int x : active) dead.emplace(x);
    }
    else {
      r = m;
      rep(i,0,n) if(!active.count(i)) dead.emplace(i);
      int q = sz(active) / distinct + 1;
      assert(q <= m);
      r = q;
      empty_all();
    }
  }

  ld R = ld(max({ADD,REM,QUE}))/ld(n);
  debug(ADD,REM,QUE);
  debug(R);
  return l;
}


// void move_inside(int i);
// void move_outside(int i);
// int press_button();

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:96:6: warning: unused variable 'R' [-Wunused-variable]
   96 |   ld R = ld(max({ADD,REM,QUE}))/ld(n);
      |      ^
# 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 1 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 1 ms 208 KB Output is correct
7 Correct 4 ms 312 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 7 ms 336 KB Output is correct
10 Correct 6 ms 312 KB Output is correct
11 Correct 3 ms 436 KB Output is correct
12 Correct 7 ms 304 KB Output is correct
13 Correct 7 ms 328 KB Output is correct
14 Correct 5 ms 336 KB Output is correct
15 Correct 5 ms 316 KB Output is correct
16 Correct 6 ms 336 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 7 ms 316 KB Output is correct
19 Correct 4 ms 316 KB Output is correct
20 Correct 6 ms 336 KB Output is correct
21 Correct 5 ms 324 KB Output is correct
22 Correct 2 ms 208 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 1 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 1 ms 208 KB Output is correct
7 Correct 4 ms 312 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 7 ms 336 KB Output is correct
10 Correct 6 ms 312 KB Output is correct
11 Correct 3 ms 436 KB Output is correct
12 Correct 7 ms 304 KB Output is correct
13 Correct 7 ms 328 KB Output is correct
14 Correct 5 ms 336 KB Output is correct
15 Correct 5 ms 316 KB Output is correct
16 Correct 6 ms 336 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 7 ms 316 KB Output is correct
19 Correct 4 ms 316 KB Output is correct
20 Correct 6 ms 336 KB Output is correct
21 Correct 5 ms 324 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 12 ms 336 KB Output is correct
24 Correct 12 ms 380 KB Output is correct
25 Correct 29 ms 468 KB Output is correct
26 Correct 24 ms 456 KB Output is correct
27 Correct 21 ms 456 KB Output is correct
28 Correct 12 ms 368 KB Output is correct
29 Correct 29 ms 468 KB Output is correct
30 Correct 57 ms 472 KB Output is correct
31 Correct 16 ms 488 KB Output is correct
32 Correct 23 ms 492 KB Output is correct
33 Correct 22 ms 528 KB Output is correct
34 Correct 17 ms 516 KB Output is correct
35 Correct 22 ms 456 KB Output is correct
36 Correct 22 ms 468 KB Output is correct
37 Correct 20 ms 456 KB Output is correct
38 Correct 24 ms 452 KB Output is correct
39 Correct 31 ms 460 KB Output is correct
40 Correct 13 ms 420 KB Output is correct
41 Correct 5 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 208 KB Output is correct
7 Correct 18 ms 388 KB Output is correct
8 Correct 32 ms 520 KB Output is correct
9 Correct 49 ms 680 KB Output is correct
10 Correct 63 ms 748 KB Output is correct
11 Correct 46 ms 788 KB Output is correct
12 Correct 24 ms 508 KB Output is correct
13 Correct 51 ms 624 KB Output is correct
14 Correct 55 ms 668 KB Output is correct
15 Correct 43 ms 704 KB Output is correct
16 Correct 46 ms 684 KB Output is correct
17 Correct 57 ms 724 KB Output is correct
18 Correct 68 ms 744 KB Output is correct
19 Correct 50 ms 712 KB Output is correct
20 Correct 55 ms 848 KB Output is correct
21 Correct 47 ms 712 KB Output is correct
22 Correct 70 ms 780 KB Output is correct
23 Correct 45 ms 608 KB Output is correct
24 Correct 46 ms 888 KB Output is correct
25 Correct 35 ms 568 KB Output is correct
26 Correct 23 ms 396 KB Output is correct
27 Correct 39 ms 736 KB Output is correct
28 Correct 55 ms 764 KB Output is correct
29 Correct 58 ms 824 KB Output is correct
30 Correct 52 ms 660 KB Output is correct
31 Correct 48 ms 672 KB Output is correct
32 Correct 53 ms 748 KB Output is correct
33 Correct 60 ms 728 KB Output is correct
34 Correct 48 ms 692 KB Output is correct
35 Correct 43 ms 772 KB Output is correct
36 Correct 44 ms 736 KB Output is correct
37 Correct 63 ms 708 KB Output is correct
38 Correct 64 ms 732 KB Output is correct
39 Correct 45 ms 736 KB Output is correct
40 Correct 58 ms 752 KB Output is correct
41 Correct 46 ms 752 KB Output is correct
42 Correct 32 ms 840 KB Output is correct
43 Correct 9 ms 392 KB Output is correct
44 Correct 36 ms 624 KB Output is correct
45 Correct 31 ms 644 KB Output is correct
46 Correct 27 ms 512 KB Output is correct
47 Correct 32 ms 592 KB Output is correct
48 Correct 38 ms 476 KB Output is correct