답안 #641475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641475 2022-09-16T19:01:11 Z TimDee 드문 곤충 (IOI22_insects) C++17
100 / 100
68 ms 432 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;

int n,d;
vector<int> in(2005,0);
vector<int> uniq;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int min_cardinality(int N) {
  n=N;
  d=0;

  vector<int> use; 
  for (int i=0; i<n; ++i) {
    use.push_back(i);
  }
  shuffle(use.begin(), use.end(),rng);

  for(int i=0; i<n; ++i) {
    move_inside(use[i]);
    int x=press_button();
    if (x>1) move_outside(use[i]);
    else { in[use[i]]=1; ++d; }
  }

  for (int i=0; i<n; ++i) if (in[i]) uniq.push_back(i);
  if (d==1) return n;
  if (d>n/2) return 1;
  if (d==2) {
    for (auto x:uniq) move_outside(x);
    int cnt=0;
    for (auto x:use) {
      move_inside(x);
      int X=press_button();
      if (X==cnt+1) ++cnt;
      else move_outside(x);
    }
    return min(cnt,n-cnt);
  }

  int l=1, r=n/d;
  int now=d;
  while (l<r) {
    vector<int> add;
    int mid=(l+r+1)>>1;
    int extra=0;
    int cnt=now;
    for (auto x:use) {
      if (in[x]) continue;
      in[x]=1;
      move_inside(x);
      int X=press_button();
      if (X>mid) {
        extra=1;
        move_outside(x);
        in[x]=0;
      } else {
        ++cnt;
        add.push_back(x);
      }
      if (cnt==mid*d) break;
    }
    if (cnt==mid*d) {
      if (extra==0) {
        return mid;
      } else {
        l=mid;
        now=cnt;
      }
    } else {
      now=cnt;
      r=mid-1;
      use=add;
      for (auto x:add) {
        --now;
        in[x]=0;
        move_outside(x);
      }
    }
  }
  return r;

}
# 결과 실행 시간 메모리 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 2 ms 208 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 3 ms 312 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 6 ms 312 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 3 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 2 ms 208 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 3 ms 312 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 6 ms 312 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 11 ms 312 KB Output is correct
25 Correct 25 ms 296 KB Output is correct
26 Correct 24 ms 316 KB Output is correct
27 Correct 20 ms 208 KB Output is correct
28 Correct 9 ms 208 KB Output is correct
29 Correct 28 ms 300 KB Output is correct
30 Correct 25 ms 208 KB Output is correct
31 Correct 27 ms 300 KB Output is correct
32 Correct 25 ms 208 KB Output is correct
33 Correct 20 ms 208 KB Output is correct
34 Correct 25 ms 208 KB Output is correct
35 Correct 27 ms 208 KB Output is correct
36 Correct 23 ms 300 KB Output is correct
37 Correct 25 ms 320 KB Output is correct
38 Correct 23 ms 208 KB Output is correct
39 Correct 18 ms 296 KB Output is correct
40 Correct 11 ms 300 KB Output is correct
41 Correct 7 ms 324 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 9 ms 208 KB Output is correct
8 Correct 16 ms 304 KB Output is correct
9 Correct 45 ms 304 KB Output is correct
10 Correct 57 ms 208 KB Output is correct
11 Correct 35 ms 208 KB Output is correct
12 Correct 17 ms 308 KB Output is correct
13 Correct 59 ms 300 KB Output is correct
14 Correct 42 ms 432 KB Output is correct
15 Correct 49 ms 308 KB Output is correct
16 Correct 55 ms 300 KB Output is correct
17 Correct 24 ms 208 KB Output is correct
18 Correct 47 ms 308 KB Output is correct
19 Correct 29 ms 300 KB Output is correct
20 Correct 26 ms 208 KB Output is correct
21 Correct 63 ms 312 KB Output is correct
22 Correct 49 ms 340 KB Output is correct
23 Correct 37 ms 208 KB Output is correct
24 Correct 38 ms 308 KB Output is correct
25 Correct 14 ms 336 KB Output is correct
26 Correct 17 ms 208 KB Output is correct
27 Correct 32 ms 300 KB Output is correct
28 Correct 22 ms 328 KB Output is correct
29 Correct 40 ms 304 KB Output is correct
30 Correct 47 ms 304 KB Output is correct
31 Correct 50 ms 208 KB Output is correct
32 Correct 44 ms 304 KB Output is correct
33 Correct 68 ms 300 KB Output is correct
34 Correct 58 ms 208 KB Output is correct
35 Correct 35 ms 304 KB Output is correct
36 Correct 57 ms 304 KB Output is correct
37 Correct 49 ms 308 KB Output is correct
38 Correct 44 ms 304 KB Output is correct
39 Correct 32 ms 304 KB Output is correct
40 Correct 41 ms 300 KB Output is correct
41 Correct 40 ms 320 KB Output is correct
42 Correct 46 ms 308 KB Output is correct
43 Correct 16 ms 208 KB Output is correct
44 Correct 48 ms 308 KB Output is correct
45 Correct 40 ms 208 KB Output is correct
46 Correct 22 ms 208 KB Output is correct
47 Correct 22 ms 328 KB Output is correct
48 Correct 31 ms 308 KB Output is correct