답안 #627867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627867 2022-08-13T00:22:31 Z Fischer 드문 곤충 (IOI22_insects) C++17
100 / 100
59 ms 336 KB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;

const int maxn = 2010;
int in[maxn];
vector<bool> memo;
int n, c;
int base;
vector<int> id;

void put(int x) {
  move_inside(x);
  //memo[x] = 1;
}

void pop(int x) {
  move_outside(x);
  //memo[x] = 0;
}

map<vector<bool>, int> mapMemo;
bool last[maxn];
int push() {
  return press_button();
  
  if (mapMemo.count(memo)) return mapMemo[memo];

  for (int i = 0; i < n; ++i) {
    if (last[i] != (in[i] != 0)) {
      if (last[i]) move_outside(i);
      else move_inside(i);
      last[i] ^= 1;
    } 
  }

  return mapMemo[memo] = press_button();
}

bool p(int x) {  
  int len = base;
  for (int i:id) {
    if (in[i] == -1) continue;
    if (len == x * c) break;
    put(i);
    in[i] = 1;
    if (push() > x) {
      pop(i);
      in[i] = 0;
    } else {
      len += 1;
    }
  }

  if (len == x * c) {
    for (int i=0;i<n; ++i) {
      if (in[i] == 1) {
        in[i] = -1;
        base += 1;
      }
    }
  } else {
    for (int i=0;i<n;++i) {
      if (in[i] == 1) {
        pop(i);
        in[i] = 0;
      } else {
        in[i] = -1;
      }
    }
  }

  return len == x * c;
}

int min_cardinality(int N) {
  n = N;
  id.resize(n);
  iota(id.begin(), id.end(), 0);
  random_shuffle(id.begin(), id.end());
  memo.assign(n, 0);
  c = 0;  
  for (int i=0; i<n; ++i) {
      put(i);
      in[i] = -1;
      if (push() == 1) c += 1;
      else pop(i), in[i] = 0; 
  }
  base = c;

  if (c == 1) return N;
  if (c == N) return 1;

  int lo = 1, hi = N / c+1;
  while (hi-lo>1) {
    int mid = (lo + hi) / 2;
    if (p(mid)) lo = mid;
    else hi = mid;
  }

  return lo;
}
# 결과 실행 시간 메모리 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 0 ms 244 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 4 ms 304 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 5 ms 244 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 8 ms 256 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 3 ms 308 KB Output is correct
22 Correct 1 ms 208 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 0 ms 244 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 4 ms 304 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 5 ms 244 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 8 ms 256 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 3 ms 308 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 11 ms 208 KB Output is correct
25 Correct 26 ms 208 KB Output is correct
26 Correct 27 ms 256 KB Output is correct
27 Correct 24 ms 312 KB Output is correct
28 Correct 16 ms 208 KB Output is correct
29 Correct 25 ms 208 KB Output is correct
30 Correct 18 ms 312 KB Output is correct
31 Correct 19 ms 208 KB Output is correct
32 Correct 19 ms 316 KB Output is correct
33 Correct 22 ms 208 KB Output is correct
34 Correct 24 ms 208 KB Output is correct
35 Correct 19 ms 308 KB Output is correct
36 Correct 24 ms 208 KB Output is correct
37 Correct 21 ms 208 KB Output is correct
38 Correct 24 ms 316 KB Output is correct
39 Correct 19 ms 308 KB Output is correct
40 Correct 14 ms 208 KB Output is correct
41 Correct 11 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 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 15 ms 208 KB Output is correct
8 Correct 15 ms 208 KB Output is correct
9 Correct 42 ms 208 KB Output is correct
10 Correct 43 ms 208 KB Output is correct
11 Correct 34 ms 304 KB Output is correct
12 Correct 28 ms 208 KB Output is correct
13 Correct 30 ms 300 KB Output is correct
14 Correct 27 ms 300 KB Output is correct
15 Correct 29 ms 208 KB Output is correct
16 Correct 25 ms 208 KB Output is correct
17 Correct 39 ms 208 KB Output is correct
18 Correct 26 ms 208 KB Output is correct
19 Correct 59 ms 208 KB Output is correct
20 Correct 46 ms 208 KB Output is correct
21 Correct 49 ms 316 KB Output is correct
22 Correct 34 ms 300 KB Output is correct
23 Correct 49 ms 316 KB Output is correct
24 Correct 45 ms 208 KB Output is correct
25 Correct 25 ms 208 KB Output is correct
26 Correct 18 ms 208 KB Output is correct
27 Correct 48 ms 208 KB Output is correct
28 Correct 37 ms 208 KB Output is correct
29 Correct 27 ms 208 KB Output is correct
30 Correct 42 ms 208 KB Output is correct
31 Correct 52 ms 208 KB Output is correct
32 Correct 47 ms 208 KB Output is correct
33 Correct 40 ms 208 KB Output is correct
34 Correct 43 ms 208 KB Output is correct
35 Correct 41 ms 212 KB Output is correct
36 Correct 38 ms 208 KB Output is correct
37 Correct 51 ms 208 KB Output is correct
38 Correct 47 ms 336 KB Output is correct
39 Correct 51 ms 208 KB Output is correct
40 Correct 53 ms 336 KB Output is correct
41 Correct 41 ms 208 KB Output is correct
42 Correct 36 ms 208 KB Output is correct
43 Correct 12 ms 208 KB Output is correct
44 Correct 30 ms 208 KB Output is correct
45 Correct 42 ms 208 KB Output is correct
46 Correct 29 ms 208 KB Output is correct
47 Correct 28 ms 208 KB Output is correct
48 Correct 23 ms 208 KB Output is correct