Submission #627240

# Submission time Handle Problem Language Result Execution time Memory
627240 2022-08-12T11:37:36 Z model_code Rarest Insects (IOI22_insects) C++17
99.91 / 100
98 ms 368 KB
// correct/solution-prabowo-shuffle.cpp
#include "insects.h"

#include <algorithm>
#include <map>
#include <numeric>
#include <random>
#include <vector>

std::vector<int> idx;
void _move_inside(int i) { move_inside(idx[i]); }
void _move_outside(int i) { move_outside(idx[i]); }
int _press_button() { return press_button(); }

int min_cardinality(int N) {
  idx.resize(N);
  std::iota(idx.begin(), idx.end(), 0);
  std::shuffle(idx.begin(), idx.end(), std::mt19937());

  std::vector<int> insects(N);
  std::iota(insects.begin(), insects.end(), 0);

  std::vector<bool> isInside(N);

  // Count distincts
  std::vector<int> insides, outsides;
  int inside = 0;
  for (int insect : insects) {
    _move_inside(insect);
    if (_press_button() > 1) {
      _move_outside(insect);
      outsides.push_back(insect);
    } else {
      insides.push_back(insect);
      ++inside;
    }
  }
  int distinct = inside;
  insects = outsides;

  int l = 1, r = N / distinct;
  int ans = -1;
  while (l <= r) {
    int mid = (l + r + 1) / 2;

    insides.clear(); outsides.clear();
    for (int insect : insects) {
      _move_inside(insect);
      if (_press_button() > mid) {
        _move_outside(insect);
        outsides.push_back(insect);
      } else {
        insides.push_back(insect);
        ++inside;
      }
    }

    if (inside == mid * distinct) {
      ans = mid;
      l = mid + 1;
      insects = outsides;
    } else {
      r = mid - 1;
      insects = insides;
      for (int insect : insects) {
        _move_outside(insect);
        --inside;
      }
    }
  }

  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 6 ms 252 KB Output is correct
10 Correct 4 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 6 ms 208 KB Output is correct
14 Correct 3 ms 236 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 6 ms 288 KB Output is correct
18 Correct 7 ms 236 KB Output is correct
19 Correct 7 ms 220 KB Output is correct
20 Correct 5 ms 220 KB Output is correct
21 Correct 3 ms 220 KB Output is correct
22 Correct 4 ms 220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 6 ms 252 KB Output is correct
10 Correct 4 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 6 ms 208 KB Output is correct
14 Correct 3 ms 236 KB Output is correct
15 Correct 6 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 6 ms 288 KB Output is correct
18 Correct 7 ms 236 KB Output is correct
19 Correct 7 ms 220 KB Output is correct
20 Correct 5 ms 220 KB Output is correct
21 Correct 3 ms 220 KB Output is correct
22 Correct 4 ms 220 KB Output is correct
23 Correct 28 ms 220 KB Output is correct
24 Correct 5 ms 220 KB Output is correct
25 Correct 21 ms 236 KB Output is correct
26 Correct 13 ms 312 KB Output is correct
27 Correct 24 ms 316 KB Output is correct
28 Correct 12 ms 220 KB Output is correct
29 Correct 33 ms 300 KB Output is correct
30 Correct 17 ms 296 KB Output is correct
31 Correct 22 ms 300 KB Output is correct
32 Correct 20 ms 304 KB Output is correct
33 Correct 14 ms 208 KB Output is correct
34 Correct 38 ms 300 KB Output is correct
35 Correct 36 ms 300 KB Output is correct
36 Correct 31 ms 284 KB Output is correct
37 Correct 18 ms 304 KB Output is correct
38 Correct 21 ms 288 KB Output is correct
39 Correct 24 ms 304 KB Output is correct
40 Correct 15 ms 304 KB Output is correct
41 Correct 19 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 216 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 236 KB Output is correct
7 Correct 49 ms 312 KB Output is correct
8 Correct 19 ms 304 KB Output is correct
9 Correct 66 ms 312 KB Output is correct
10 Correct 84 ms 308 KB Output is correct
11 Correct 56 ms 312 KB Output is correct
12 Correct 33 ms 316 KB Output is correct
13 Correct 48 ms 336 KB Output is correct
14 Correct 48 ms 208 KB Output is correct
15 Correct 54 ms 208 KB Output is correct
16 Correct 37 ms 316 KB Output is correct
17 Correct 58 ms 336 KB Output is correct
18 Correct 61 ms 308 KB Output is correct
19 Correct 54 ms 360 KB Output is correct
20 Correct 98 ms 304 KB Output is correct
21 Correct 78 ms 300 KB Output is correct
22 Correct 61 ms 300 KB Output is correct
23 Correct 49 ms 312 KB Output is correct
24 Correct 23 ms 304 KB Output is correct
25 Correct 17 ms 320 KB Output is correct
26 Correct 14 ms 344 KB Output is correct
27 Correct 43 ms 208 KB Output is correct
28 Correct 36 ms 316 KB Output is correct
29 Correct 49 ms 308 KB Output is correct
30 Correct 52 ms 316 KB Output is correct
31 Partially correct 49 ms 304 KB Output is partially correct
32 Partially correct 55 ms 316 KB Output is partially correct
33 Correct 65 ms 308 KB Output is correct
34 Correct 46 ms 300 KB Output is correct
35 Correct 38 ms 292 KB Output is correct
36 Correct 84 ms 308 KB Output is correct
37 Partially correct 62 ms 292 KB Output is partially correct
38 Partially correct 53 ms 308 KB Output is partially correct
39 Correct 44 ms 304 KB Output is correct
40 Correct 80 ms 324 KB Output is correct
41 Correct 84 ms 304 KB Output is correct
42 Correct 45 ms 292 KB Output is correct
43 Correct 11 ms 304 KB Output is correct
44 Correct 21 ms 312 KB Output is correct
45 Correct 47 ms 296 KB Output is correct
46 Correct 40 ms 368 KB Output is correct
47 Correct 32 ms 308 KB Output is correct
48 Correct 35 ms 208 KB Output is correct