답안 #628136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628136 2022-08-13T06:01:56 Z Cross_Ratio 드문 곤충 (IOI22_insects) C++17
100 / 100
62 ms 1404 KB
//#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
map<int,set<int>> MS;
void move_inside(int);
void move_outside(int);
int press_button();
int min_cardinality(int N) {
    int i, j;
    set<int> S, S2;
    vector<int> V;
    for(i=0;i<N;i++)V.push_back(i);
    random_shuffle(V.begin(),V.end());
    move_inside(V[0]);
    S.insert(V[0]);
    int k = 0;
    int id = -1, v = -1;
    for(j=1;j<N;j++) {
        i = V[j];
        move_inside(i);
        S.insert(i);
        int c = press_button();
        if(c >= 2&&j!=N-1) {
            move_outside(i);
            S.erase(i);
        }
        if(j==N-1) {
            k = S.size();
            if(c>=2) {
                id = V[N-1];
                v = 2;
                k--;
            }
        }
    }
    for(i=0;i<N;i++) S2.insert(i);
    MS[1] = S;
    int s = 1, e = N/k+1;
    if(e==s+1) return s;
    int mid = (s+e)/2;
    for(int j : S2) {
        i = V[j];
        if(S.find(i)==S.end()) {
            move_inside(i);
            S.insert(i);
            int c = press_button();
            if(c>v) {
                v = c;
                id = j;
            }
            if(c >= mid+1) {
                move_outside(i);
                S.erase(i);
            }
            if(S.size()==k*mid) break;
        }
        if(S.size()==k*mid) break;
    }
    MS[mid] = S;
    while(s+1<e) {
        int mid = (s+e)/2;
        if(S.size()==k*mid) {
            s = mid;
            if(mid+1>=e) break;
            mid = (s+e)/2;
            for(int j : S2) {
                i = V[j];
                if(S.size()==k*mid) break;
                if(S.find(i)==S.end()) {
                    move_inside(i);
                    S.insert(i);
                    int c = press_button();
                    if(c>v) {
                        v = c;
                        id = j;
                    }
                    if(c >= mid+1) {
                        move_outside(i);
                        S.erase(i);
                    }
                    if(S.size()==k*mid) break;
                }
                if(S.size()==k*mid) break;
            }
            MS[mid] = S;
        }
        else {
            e = mid;
            if(s+1>=e) break;
            vector<int> era;
            for(int m : S2) {
                if(S.find(V[m])==S.end()) era.push_back(m);
            }
            for(int i : era) S2.erase(i);
            S2.erase(id);
            if(id>=0&&id<N)S.erase(V[id]);
            mid = (s+e)/2;
            auto it = MS.upper_bound(mid);
            it--;
            set<int> S3 = it->second;
            set<int> S4;
            for(i=0;i<N;i++) {
                if(S3.find(i)!=S3.end()&&S.find(i)==S.end()) {
                    move_inside(i);
                    S.insert(i);
                }
                if(S3.find(i)==S3.end()&&S.find(i)!=S.end()) {
                    move_outside(i);
                    S.erase(i);
                    S4.insert(i);
                }
            }
            id = -1;
            v = -1;
            for(int i : S4) {
                if(S.find(i)==S.end()) {
                    move_inside(i);
                    S.insert(i);
                    int c = press_button();
                    if(c>v) {
                        v = c;
                        id = j;
                    }
                    if(c >= mid+1) {
                        move_outside(i);
                        S.erase(i);
                    }
                    if(S.size()==k*mid) break;
                }
                if(S.size()==k*mid) break;
            }
            MS[mid] = S;
        }
    }
    return s;
}


Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:55:24: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |             if(S.size()==k*mid) break;
      |                ~~~~~~~~^~~~~~~
insects.cpp:57:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |         if(S.size()==k*mid) break;
      |            ~~~~~~~~^~~~~~~
insects.cpp:62:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |         if(S.size()==k*mid) {
      |            ~~~~~~~~^~~~~~~
insects.cpp:68:28: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |                 if(S.size()==k*mid) break;
      |                    ~~~~~~~~^~~~~~~
insects.cpp:81:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |                     if(S.size()==k*mid) break;
      |                        ~~~~~~~~^~~~~~~
insects.cpp:83:28: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   83 |                 if(S.size()==k*mid) break;
      |                    ~~~~~~~~^~~~~~~
insects.cpp:128:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  128 |                     if(S.size()==k*mid) break;
      |                        ~~~~~~~~^~~~~~~
insects.cpp:130:28: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  130 |                 if(S.size()==k*mid) break;
      |                    ~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 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 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 7 ms 300 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 336 KB Output is correct
9 Correct 4 ms 300 KB Output is correct
10 Correct 3 ms 300 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 2 ms 304 KB Output is correct
15 Correct 6 ms 336 KB Output is correct
16 Correct 6 ms 316 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 5 ms 320 KB Output is correct
19 Correct 6 ms 304 KB Output is correct
20 Correct 7 ms 304 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 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 7 ms 300 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 336 KB Output is correct
9 Correct 4 ms 300 KB Output is correct
10 Correct 3 ms 300 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 2 ms 304 KB Output is correct
15 Correct 6 ms 336 KB Output is correct
16 Correct 6 ms 316 KB Output is correct
17 Correct 6 ms 336 KB Output is correct
18 Correct 5 ms 320 KB Output is correct
19 Correct 6 ms 304 KB Output is correct
20 Correct 7 ms 304 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 20 ms 680 KB Output is correct
24 Correct 10 ms 336 KB Output is correct
25 Correct 24 ms 472 KB Output is correct
26 Correct 29 ms 432 KB Output is correct
27 Correct 12 ms 304 KB Output is correct
28 Correct 9 ms 336 KB Output is correct
29 Correct 29 ms 428 KB Output is correct
30 Correct 22 ms 380 KB Output is correct
31 Correct 19 ms 604 KB Output is correct
32 Correct 28 ms 612 KB Output is correct
33 Correct 27 ms 560 KB Output is correct
34 Correct 31 ms 556 KB Output is correct
35 Correct 25 ms 548 KB Output is correct
36 Correct 24 ms 488 KB Output is correct
37 Correct 27 ms 424 KB Output is correct
38 Correct 18 ms 456 KB Output is correct
39 Correct 18 ms 396 KB Output is correct
40 Correct 13 ms 320 KB Output is correct
41 Correct 11 ms 320 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 0 ms 236 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 35 ms 1404 KB Output is correct
8 Correct 23 ms 456 KB Output is correct
9 Correct 37 ms 1032 KB Output is correct
10 Correct 35 ms 656 KB Output is correct
11 Correct 40 ms 408 KB Output is correct
12 Correct 25 ms 440 KB Output is correct
13 Correct 53 ms 456 KB Output is correct
14 Correct 56 ms 420 KB Output is correct
15 Correct 45 ms 1056 KB Output is correct
16 Correct 38 ms 1032 KB Output is correct
17 Correct 43 ms 964 KB Output is correct
18 Correct 55 ms 940 KB Output is correct
19 Correct 47 ms 968 KB Output is correct
20 Correct 34 ms 944 KB Output is correct
21 Correct 50 ms 624 KB Output is correct
22 Correct 41 ms 560 KB Output is correct
23 Correct 47 ms 440 KB Output is correct
24 Correct 44 ms 584 KB Output is correct
25 Correct 20 ms 456 KB Output is correct
26 Correct 22 ms 468 KB Output is correct
27 Correct 55 ms 800 KB Output is correct
28 Correct 41 ms 776 KB Output is correct
29 Correct 46 ms 932 KB Output is correct
30 Correct 37 ms 952 KB Output is correct
31 Correct 62 ms 728 KB Output is correct
32 Correct 60 ms 672 KB Output is correct
33 Correct 54 ms 524 KB Output is correct
34 Correct 30 ms 492 KB Output is correct
35 Correct 38 ms 808 KB Output is correct
36 Correct 51 ms 816 KB Output is correct
37 Correct 47 ms 612 KB Output is correct
38 Correct 52 ms 672 KB Output is correct
39 Correct 45 ms 772 KB Output is correct
40 Correct 44 ms 764 KB Output is correct
41 Correct 47 ms 880 KB Output is correct
42 Correct 26 ms 872 KB Output is correct
43 Correct 9 ms 336 KB Output is correct
44 Correct 22 ms 416 KB Output is correct
45 Correct 39 ms 1316 KB Output is correct
46 Correct 28 ms 480 KB Output is correct
47 Correct 28 ms 460 KB Output is correct
48 Correct 32 ms 456 KB Output is correct