답안 #713250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713250 2023-03-21T13:30:03 Z KoD 드문 곤충 (IOI22_insects) C++17
100 / 100
67 ms 456 KB
#include "insects.h"

#include <vector>
#include <random>

int min_cardinality(int N) {
  int kinds = 0;
  std::vector<int> type(N);
  for (int i = 0; i < N; ++i) {
    move_inside(i);
    if (press_button() > 1) {
      move_outside(i);
    } else {
      kinds += 1;
      type[i] = 1;
    }
  }
  auto check = [&](int thres) {
    int cnt = 0;
    std::vector<int> in, out;
    for (int i = 0; i < N; ++i) {
      if (type[i] == 1) {
        cnt += 1;
      } else if (type[i] == 0) {
        move_inside(i);
        if (press_button() > thres) {
          move_outside(i);
          out.push_back(i);
        } else {
          in.push_back(i);
        }
      }
    }
    if (cnt + (int)in.size() == kinds * thres) {
      for (const int i : in) {
        type[i] = 1;
      }
      return true;
    } else {
      for (const int i : in) {
        move_outside(i);
      }
      for (const int i : out) {
        type[i] = -1;
      }
      return false;
    }
  };
  int ok = 1, ng = N / kinds + 1;
  std::default_random_engine gen(0xABCDEF);
  std::uniform_int_distribution flag(0, 1);
  while (ng - ok > 1) {
    int md = (ok + ng) / 2;
    if ((ok + ng) % 2 == 1 and flag(gen)) {
      md += 1;
    }
    (check(md) ? ok : ng) = md;
  }
  return ok;
}
# 결과 실행 시간 메모리 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 0 ms 208 KB Output is correct
6 Correct 6 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 3 ms 288 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 288 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 6 ms 292 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 7 ms 288 KB Output is correct
17 Correct 8 ms 292 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 5 ms 284 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 208 KB Output is correct
6 Correct 6 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 3 ms 288 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 288 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 6 ms 292 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 7 ms 288 KB Output is correct
17 Correct 8 ms 292 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 5 ms 284 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 29 ms 208 KB Output is correct
24 Correct 11 ms 208 KB Output is correct
25 Correct 23 ms 280 KB Output is correct
26 Correct 24 ms 208 KB Output is correct
27 Correct 21 ms 208 KB Output is correct
28 Correct 6 ms 208 KB Output is correct
29 Correct 27 ms 296 KB Output is correct
30 Correct 25 ms 268 KB Output is correct
31 Correct 21 ms 280 KB Output is correct
32 Correct 26 ms 208 KB Output is correct
33 Correct 29 ms 208 KB Output is correct
34 Correct 23 ms 272 KB Output is correct
35 Correct 25 ms 208 KB Output is correct
36 Correct 21 ms 268 KB Output is correct
37 Correct 28 ms 208 KB Output is correct
38 Correct 21 ms 296 KB Output is correct
39 Correct 19 ms 208 KB Output is correct
40 Correct 16 ms 208 KB Output is correct
41 Correct 10 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 55 ms 284 KB Output is correct
8 Correct 16 ms 208 KB Output is correct
9 Correct 45 ms 284 KB Output is correct
10 Correct 42 ms 208 KB Output is correct
11 Correct 56 ms 280 KB Output is correct
12 Correct 20 ms 276 KB Output is correct
13 Correct 65 ms 284 KB Output is correct
14 Correct 43 ms 292 KB Output is correct
15 Correct 62 ms 208 KB Output is correct
16 Correct 35 ms 272 KB Output is correct
17 Correct 34 ms 276 KB Output is correct
18 Correct 55 ms 284 KB Output is correct
19 Correct 37 ms 284 KB Output is correct
20 Correct 56 ms 284 KB Output is correct
21 Correct 31 ms 288 KB Output is correct
22 Correct 29 ms 272 KB Output is correct
23 Correct 47 ms 336 KB Output is correct
24 Correct 42 ms 284 KB Output is correct
25 Correct 30 ms 332 KB Output is correct
26 Correct 22 ms 208 KB Output is correct
27 Correct 56 ms 208 KB Output is correct
28 Correct 30 ms 276 KB Output is correct
29 Correct 46 ms 208 KB Output is correct
30 Correct 63 ms 280 KB Output is correct
31 Correct 27 ms 280 KB Output is correct
32 Correct 34 ms 456 KB Output is correct
33 Correct 67 ms 284 KB Output is correct
34 Correct 50 ms 208 KB Output is correct
35 Correct 53 ms 208 KB Output is correct
36 Correct 57 ms 280 KB Output is correct
37 Correct 57 ms 404 KB Output is correct
38 Correct 44 ms 280 KB Output is correct
39 Correct 54 ms 292 KB Output is correct
40 Correct 49 ms 280 KB Output is correct
41 Correct 56 ms 284 KB Output is correct
42 Correct 47 ms 284 KB Output is correct
43 Correct 7 ms 208 KB Output is correct
44 Correct 38 ms 408 KB Output is correct
45 Correct 55 ms 272 KB Output is correct
46 Correct 23 ms 284 KB Output is correct
47 Correct 24 ms 328 KB Output is correct
48 Correct 20 ms 276 KB Output is correct