답안 #641473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641473 2022-09-16T18:59:23 Z TimDee 드문 곤충 (IOI22_insects) C++17
100 / 100
55 ms 316 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;
    //shuffle(use.begin(), use.end(),rng);
    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 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 3 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 5 ms 308 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 312 KB Output is correct
18 Correct 8 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 5 ms 316 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 1 ms 304 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 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 3 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 5 ms 308 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 312 KB Output is correct
18 Correct 8 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 5 ms 316 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 7 ms 208 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 17 ms 208 KB Output is correct
26 Correct 30 ms 304 KB Output is correct
27 Correct 8 ms 208 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 26 ms 308 KB Output is correct
30 Correct 29 ms 208 KB Output is correct
31 Correct 19 ms 208 KB Output is correct
32 Correct 28 ms 208 KB Output is correct
33 Correct 20 ms 208 KB Output is correct
34 Correct 17 ms 208 KB Output is correct
35 Correct 17 ms 208 KB Output is correct
36 Correct 26 ms 208 KB Output is correct
37 Correct 23 ms 296 KB Output is correct
38 Correct 26 ms 208 KB Output is correct
39 Correct 22 ms 208 KB Output is correct
40 Correct 16 ms 208 KB Output is correct
41 Correct 8 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 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 14 ms 208 KB Output is correct
8 Correct 17 ms 304 KB Output is correct
9 Correct 42 ms 208 KB Output is correct
10 Correct 51 ms 304 KB Output is correct
11 Correct 27 ms 208 KB Output is correct
12 Correct 28 ms 308 KB Output is correct
13 Correct 51 ms 208 KB Output is correct
14 Correct 45 ms 304 KB Output is correct
15 Correct 38 ms 304 KB Output is correct
16 Correct 23 ms 304 KB Output is correct
17 Correct 43 ms 208 KB Output is correct
18 Correct 34 ms 300 KB Output is correct
19 Correct 47 ms 208 KB Output is correct
20 Correct 48 ms 316 KB Output is correct
21 Correct 40 ms 304 KB Output is correct
22 Correct 52 ms 304 KB Output is correct
23 Correct 36 ms 208 KB Output is correct
24 Correct 38 ms 300 KB Output is correct
25 Correct 26 ms 308 KB Output is correct
26 Correct 20 ms 208 KB Output is correct
27 Correct 43 ms 300 KB Output is correct
28 Correct 50 ms 208 KB Output is correct
29 Correct 20 ms 208 KB Output is correct
30 Correct 39 ms 208 KB Output is correct
31 Correct 54 ms 300 KB Output is correct
32 Correct 38 ms 308 KB Output is correct
33 Correct 37 ms 308 KB Output is correct
34 Correct 43 ms 304 KB Output is correct
35 Correct 45 ms 208 KB Output is correct
36 Correct 28 ms 304 KB Output is correct
37 Correct 55 ms 300 KB Output is correct
38 Correct 51 ms 208 KB Output is correct
39 Correct 38 ms 308 KB Output is correct
40 Correct 51 ms 300 KB Output is correct
41 Correct 47 ms 304 KB Output is correct
42 Correct 42 ms 208 KB Output is correct
43 Correct 18 ms 208 KB Output is correct
44 Correct 50 ms 300 KB Output is correct
45 Correct 39 ms 208 KB Output is correct
46 Correct 25 ms 208 KB Output is correct
47 Correct 22 ms 300 KB Output is correct
48 Correct 27 ms 300 KB Output is correct