답안 #629196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629196 2022-08-14T09:06:45 Z urd05 드문 곤충 (IOI22_insects) C++17
100 / 100
75 ms 312 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<int> v;
bool in[2000];
bool vis[2000];
int mnv=1;
int val;
int n;
 
void mi(int i) {
    in[i]=true;
    move_inside(v[i]);
}
 
void mo(int i) {
    in[i]=false;
    move_outside(v[i]);
}
 
int pb() {
    return press_button();
}
 
void clean() {
    for(int i=0;i<n;i++) {
        if (in[i]) {
            mo(i);
        }
    }
}
 
int f() {
    int ret=0;
    for(int i=0;i<n;i++) {
        mi(i);
        int got=pb();
        if (got>1) {
            mo(i);
        }
        else {
            vis[i]=true;
            ret++;
        }
    }
    clean();
    return ret;
}
 
bool isp(int x) {
    x-=mnv;
    vector<int> save;
    vector<int> out;
  int pr=0;
    for(int i=0;i<n;i++) {
        if (vis[i]) {
            continue;
        }
        mi(i);
        int got=pb();
        if (got>x) {
            mo(i);
            out.push_back(i);
        }
        else {
          if (pr==x-1&&got==x) {
            out.push_back(i);
          }
            save.push_back(i);
        }
      pr=got;
    }
    clean();
    if (save.size()==x*val) {
        for(int i=0;i<save.size();i++) {
            vis[save[i]]=true;
        }
        mnv+=x;
        return true;
    }
    for(int i=0;i<out.size();i++) {
        vis[out[i]]=true;
    }
    return false;
}
 
int min_cardinality(int N) {
    n=N;
    for(int i=0;i<n;i++) {
        v.push_back(i);
    }
    srand(int(time(NULL)));
    random_shuffle(v.begin(),v.end());
    val=f();
    if (val<4) {
        memset(vis,0,sizeof(vis));
        int sum=n;
        int ret=n;
        for(int i=0;i<val-1;i++) {
            int now=0;
            while (vis[now]) {
                now++;
            }
            mi(now);
            vis[now]=true;
            now++;
            int cnt=1;
            while (now<n) {
                while (now<n&&vis[now]) {
                    now++;
                }
                if (now>=n) {
                    break;
                }
                mi(now);
                int got=pb();
                if (got==cnt) {
                    mo(now);
                }
                else {
                    vis[now]=true;
                    cnt++;
                }
              now++;
            }
            clean();
            ret=min(ret,cnt);
            sum-=cnt;
        }
        return min(sum,ret);
    }
    int lo=1; //ans>=lo
    int hi=n/val+1; //ans<hi
    while (lo+1<hi) {
        int mid=(lo+hi+(hi-lo>5?1:0))/2;
        if (isp(mid)) {
            lo=mid;
        }
        else {
            hi=mid;
        }
    }
  return lo;
}

Compilation message

insects.cpp: In function 'bool isp(int)':
insects.cpp:75:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   75 |     if (save.size()==x*val) {
      |         ~~~~~~~~~~~^~~~~~~
insects.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int i=0;i<save.size();i++) {
      |                     ~^~~~~~~~~~~~
insects.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i=0;i<out.size();i++) {
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 272 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 5 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 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 4 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 5 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 5 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 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 272 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 5 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 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 4 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 5 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 5 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 11 ms 208 KB Output is correct
24 Correct 11 ms 208 KB Output is correct
25 Correct 28 ms 292 KB Output is correct
26 Correct 23 ms 208 KB Output is correct
27 Correct 13 ms 292 KB Output is correct
28 Correct 10 ms 208 KB Output is correct
29 Correct 27 ms 208 KB Output is correct
30 Correct 32 ms 208 KB Output is correct
31 Correct 24 ms 292 KB Output is correct
32 Correct 25 ms 208 KB Output is correct
33 Correct 30 ms 208 KB Output is correct
34 Correct 23 ms 208 KB Output is correct
35 Correct 24 ms 292 KB Output is correct
36 Correct 36 ms 208 KB Output is correct
37 Correct 24 ms 288 KB Output is correct
38 Correct 24 ms 296 KB Output is correct
39 Correct 22 ms 292 KB Output is correct
40 Correct 21 ms 208 KB Output is correct
41 Correct 11 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 9 ms 208 KB Output is correct
8 Correct 30 ms 292 KB Output is correct
9 Correct 65 ms 300 KB Output is correct
10 Correct 75 ms 296 KB Output is correct
11 Correct 32 ms 208 KB Output is correct
12 Correct 35 ms 292 KB Output is correct
13 Correct 46 ms 312 KB Output is correct
14 Correct 26 ms 308 KB Output is correct
15 Correct 24 ms 300 KB Output is correct
16 Correct 57 ms 304 KB Output is correct
17 Correct 58 ms 300 KB Output is correct
18 Correct 55 ms 304 KB Output is correct
19 Correct 60 ms 292 KB Output is correct
20 Correct 49 ms 296 KB Output is correct
21 Correct 48 ms 292 KB Output is correct
22 Correct 41 ms 296 KB Output is correct
23 Correct 55 ms 296 KB Output is correct
24 Correct 48 ms 304 KB Output is correct
25 Correct 32 ms 300 KB Output is correct
26 Correct 27 ms 208 KB Output is correct
27 Correct 66 ms 304 KB Output is correct
28 Correct 26 ms 300 KB Output is correct
29 Correct 38 ms 300 KB Output is correct
30 Correct 57 ms 300 KB Output is correct
31 Correct 56 ms 304 KB Output is correct
32 Correct 47 ms 308 KB Output is correct
33 Correct 30 ms 304 KB Output is correct
34 Correct 35 ms 208 KB Output is correct
35 Correct 34 ms 304 KB Output is correct
36 Correct 31 ms 300 KB Output is correct
37 Correct 59 ms 296 KB Output is correct
38 Correct 47 ms 208 KB Output is correct
39 Correct 44 ms 292 KB Output is correct
40 Correct 49 ms 208 KB Output is correct
41 Correct 57 ms 208 KB Output is correct
42 Correct 58 ms 208 KB Output is correct
43 Correct 11 ms 208 KB Output is correct
44 Correct 59 ms 296 KB Output is correct
45 Correct 43 ms 296 KB Output is correct
46 Correct 14 ms 300 KB Output is correct
47 Correct 27 ms 208 KB Output is correct
48 Correct 24 ms 208 KB Output is correct