Submission #627230

# Submission time Handle Problem Language Result Execution time Memory
627230 2022-08-12T11:36:58 Z model_code Rarest Insects (IOI22_insects) C++17
99.89 / 100
115 ms 428 KB
// correct/solution-hocky-blacklist-binser.cpp
#include "insects.h"

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

int min_cardinality(int N) {

  vector<int> device;
  vector<int> checking_set;

  for (int i = 0; i < N; i++) {
    move_inside(i);
    int max_occurrence = press_button();
    if (max_occurrence == 2) {
      move_outside(i);
      checking_set.push_back(i);
    } else {
      device.push_back(i);
    }
  }

  int distinct = device.size();
  auto get_bounds = [&](int device_size, int checking_size) -> pair<int, int> {
    return {device_size / distinct, (device_size + checking_size) / distinct};
  };

  vector <int> blacklist(N);
  pair<int, int> bounds = get_bounds(device.size(), checking_set.size());

  vector<pair<int, int>> just_moved;
  do {
    if (bounds.first == bounds.second) {
      return bounds.first;
    }
    assert(bounds.first < bounds.second);
    int middle = (bounds.first + bounds.second + 1) / 2;
    vector<int> next_checking_set;
    for (const auto &insect : checking_set) {
      if(blacklist[insect]) {
        next_checking_set.push_back(insect);
        continue;
      }
      move_inside(insect);
      int max_occurrence = press_button();
      if (max_occurrence > middle) {
        move_outside(insect);
        next_checking_set.push_back(insect);
      } else {
        just_moved.push_back({insect, max_occurrence});
      }
    }
    if ((int) just_moved.size() + (int) device.size() == distinct * middle) {
      // Increase the lower bound
      for (const auto &insect : just_moved) {
        device.push_back(insect.first);
      }
      swap(checking_set, next_checking_set);
      bounds = get_bounds(device.size(), checking_set.size());
      just_moved.clear();
      blacklist.assign(N, 0);
    } else {

      // Decrease the upper bound
      bounds = get_bounds(device.size(), just_moved.size());
      if (bounds.first < bounds.second) {
        checking_set.clear();
        int next_middle = (bounds.first + bounds.second + 1) / 2;
        int pushed = 0;
        for (int i = 0; i < (int) just_moved.size(); i++) {
          const auto &insect = just_moved[i];
          if (insect.second <= next_middle) {
            pushed++;
          } else {
            if(i > 0 && just_moved[i - 1].second < just_moved[i].second) blacklist[insect.first] = 1;
            move_outside(insect.first);
            checking_set.push_back(insect.first);
          }
        }
        just_moved.resize(pushed);
      } else {
        return bounds.first;
      }
    }
  } while (true);

  return 0;
}
# 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 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 9 ms 300 KB Output is correct
7 Correct 2 ms 296 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 7 ms 256 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
11 Correct 2 ms 300 KB Output is correct
12 Correct 8 ms 296 KB Output is correct
13 Correct 9 ms 208 KB Output is correct
14 Correct 9 ms 256 KB Output is correct
15 Correct 4 ms 296 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 5 ms 208 KB Output is correct
21 Correct 5 ms 208 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 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 9 ms 300 KB Output is correct
7 Correct 2 ms 296 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 7 ms 256 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
11 Correct 2 ms 300 KB Output is correct
12 Correct 8 ms 296 KB Output is correct
13 Correct 9 ms 208 KB Output is correct
14 Correct 9 ms 256 KB Output is correct
15 Correct 4 ms 296 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 5 ms 208 KB Output is correct
21 Correct 5 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 22 ms 348 KB Output is correct
24 Correct 9 ms 292 KB Output is correct
25 Correct 34 ms 304 KB Output is correct
26 Correct 28 ms 300 KB Output is correct
27 Correct 33 ms 304 KB Output is correct
28 Correct 10 ms 360 KB Output is correct
29 Correct 12 ms 312 KB Output is correct
30 Correct 38 ms 284 KB Output is correct
31 Correct 33 ms 300 KB Output is correct
32 Correct 32 ms 296 KB Output is correct
33 Correct 37 ms 336 KB Output is correct
34 Correct 13 ms 308 KB Output is correct
35 Correct 30 ms 300 KB Output is correct
36 Correct 26 ms 300 KB Output is correct
37 Correct 18 ms 308 KB Output is correct
38 Correct 18 ms 304 KB Output is correct
39 Correct 29 ms 208 KB Output is correct
40 Correct 12 ms 300 KB Output is correct
41 Correct 13 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 224 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 27 ms 304 KB Output is correct
8 Correct 35 ms 292 KB Output is correct
9 Correct 48 ms 308 KB Output is correct
10 Correct 40 ms 312 KB Output is correct
11 Correct 24 ms 308 KB Output is correct
12 Correct 24 ms 304 KB Output is correct
13 Correct 38 ms 300 KB Output is correct
14 Correct 43 ms 284 KB Output is correct
15 Correct 84 ms 316 KB Output is correct
16 Correct 115 ms 300 KB Output is correct
17 Correct 63 ms 308 KB Output is correct
18 Correct 49 ms 316 KB Output is correct
19 Correct 32 ms 312 KB Output is correct
20 Correct 79 ms 316 KB Output is correct
21 Correct 69 ms 308 KB Output is correct
22 Correct 54 ms 312 KB Output is correct
23 Correct 43 ms 296 KB Output is correct
24 Correct 36 ms 304 KB Output is correct
25 Correct 30 ms 308 KB Output is correct
26 Correct 22 ms 304 KB Output is correct
27 Correct 34 ms 296 KB Output is correct
28 Correct 48 ms 308 KB Output is correct
29 Partially correct 41 ms 312 KB Output is partially correct
30 Partially correct 43 ms 308 KB Output is partially correct
31 Correct 51 ms 312 KB Output is correct
32 Correct 43 ms 308 KB Output is correct
33 Correct 39 ms 304 KB Output is correct
34 Correct 60 ms 308 KB Output is correct
35 Partially correct 34 ms 304 KB Output is partially correct
36 Partially correct 65 ms 356 KB Output is partially correct
37 Correct 76 ms 312 KB Output is correct
38 Correct 46 ms 312 KB Output is correct
39 Correct 49 ms 308 KB Output is correct
40 Correct 57 ms 312 KB Output is correct
41 Partially correct 43 ms 428 KB Output is partially correct
42 Partially correct 45 ms 356 KB Output is partially correct
43 Correct 12 ms 304 KB Output is correct
44 Correct 40 ms 328 KB Output is correct
45 Correct 70 ms 280 KB Output is correct
46 Correct 26 ms 296 KB Output is correct
47 Correct 21 ms 308 KB Output is correct
48 Correct 35 ms 308 KB Output is correct