답안 #1075450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075450 2024-08-26T06:24:42 Z Zicrus 드문 곤충 (IOI22_insects) C++17
59.38 / 100
111 ms 848 KB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
 
typedef long long ll;
 
int n;
vector<bool> in;
unordered_set<int> s;
int cnt;
 
int add(int i) {
    if (in[i]) return 0;
    move_inside(i);
    cnt++;
    in[i] = true;
    return 1;
}
 
int remove(int i) {
    if (!in[i]) return 0;
    move_outside(i);
    cnt--;
    in[i] = false;
    return 1;
}
 
int min_cardinality(int N) {
    n = N;
    cnt = 0;
    mt19937 mt(time(0));
    in = vector<bool>(n);
    for (int i = 0; i < n; i++) {
        add(i);
    }
    int mx = press_button();
    int prevSz = cnt;
    while (mx > 1) {
        int cur = mx;
        while (cur == mx) {
            if (cnt > 16) {
                int i = mt()%n;
                while (!remove(i)) i = mt()%n;
                int j = mt()%n;
                while (!remove(j)) j = mt()%n;
                int i1 = mt()%n;
                while (!remove(i1)) i1 = mt()%n;
                int j1 = mt()%n;
                while (!remove(j1)) j1 = mt()%n;
                cur = press_button();
                if (cur == mx) {
                    s.insert(i);
                    s.insert(j);
                    s.insert(i1);
                    s.insert(j1);
                }
                else {
                    add(j1);
                    add(i1);
                    cur = press_button();
                    if (cur == mx) {
                        s.insert(i);
                        s.insert(j);
                    }
                    else {
                        add(j);
                        cur = press_button();
                        if (cur == mx) {
                            s.insert(i);
                            remove(j);
                        }
                        cur = mx-1;
                    }
                }
            }
            else {
                int i = mt()%n;
                while (!remove(i)) i = mt()%n;
                int j = mt()%n;
                while (!remove(j)) j = mt()%n;
                cur = press_button();
                if (cur == mx) {
                    s.insert(i);
                    s.insert(j);
                }
                else {
                    add(j);
                    cur = press_button();
                    if (cur == mx) {
                        s.insert(i);
                        remove(j);
                    }
                    cur = mx-1;
                }
            }
        }
        vector<int> s0;
        for (auto &e : s) {
            s0.push_back(e);
        }
        shuffle(s0.begin(), s0.end(), mt);
        for (int i = 0; i < s0.size(); i++) {
            if (i == s0.size()-1) {
                if (add(s0[i])) {
                    cur = press_button();
                    if (cur == mx) remove(s0[i]);
                }
                continue;
            }

            add(s0[i]);
            add(s0[i+1]);
            cur = press_button();
            if (cur == mx) {
                remove(s0[i+1]);
                cur = press_button();
                if (cur == mx) {
                    remove(s0[i]);
                }
                else {
                    i++;
                }
            }
        }
        if (cnt * mx % (mx-1) == 0 && cnt * mx / (mx-1) == prevSz) {
            break;
        }
        s.clear();
        prevSz = cnt;
        mx--;
    }
    return mx;
} 
 
#ifdef TEST
#include "grader.cpp"
#endif

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:102:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         for (int i = 0; i < s0.size(); i++) {
      |                         ~~^~~~~~~~~~~
insects.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |             if (i == s0.size()-1) {
      |                 ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 3 ms 356 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 4 ms 344 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 3 ms 356 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 4 ms 344 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 27 ms 600 KB Output is correct
27 Correct 18 ms 344 KB Output is correct
28 Correct 46 ms 848 KB Output is correct
29 Correct 21 ms 440 KB Output is correct
30 Correct 30 ms 344 KB Output is correct
31 Correct 4 ms 436 KB Output is correct
32 Correct 10 ms 344 KB Output is correct
33 Correct 10 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 7 ms 344 KB Output is correct
36 Correct 11 ms 344 KB Output is correct
37 Correct 24 ms 344 KB Output is correct
38 Correct 35 ms 452 KB Output is correct
39 Correct 34 ms 344 KB Output is correct
40 Correct 33 ms 344 KB Output is correct
41 Correct 12 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 3 ms 692 KB Output is correct
10 Partially correct 42 ms 436 KB Output is partially correct
11 Partially correct 43 ms 344 KB Output is partially correct
12 Partially correct 99 ms 420 KB Output is partially correct
13 Partially correct 41 ms 588 KB Output is partially correct
14 Partially correct 64 ms 344 KB Output is partially correct
15 Correct 5 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 17 ms 440 KB Output is correct
19 Correct 13 ms 344 KB Output is correct
20 Correct 15 ms 344 KB Output is correct
21 Partially correct 52 ms 588 KB Output is partially correct
22 Partially correct 67 ms 344 KB Output is partially correct
23 Partially correct 105 ms 672 KB Output is partially correct
24 Partially correct 56 ms 480 KB Output is partially correct
25 Partially correct 65 ms 696 KB Output is partially correct
26 Partially correct 40 ms 344 KB Output is partially correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 4 ms 440 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Partially correct 40 ms 436 KB Output is partially correct
32 Partially correct 50 ms 456 KB Output is partially correct
33 Partially correct 69 ms 580 KB Output is partially correct
34 Partially correct 61 ms 344 KB Output is partially correct
35 Correct 9 ms 440 KB Output is correct
36 Correct 8 ms 344 KB Output is correct
37 Partially correct 30 ms 588 KB Output is partially correct
38 Partially correct 42 ms 344 KB Output is partially correct
39 Correct 8 ms 344 KB Output is correct
40 Correct 5 ms 344 KB Output is correct
41 Correct 4 ms 456 KB Output is correct
42 Correct 7 ms 344 KB Output is correct
43 Partially correct 9 ms 344 KB Output is partially correct
44 Partially correct 37 ms 344 KB Output is partially correct
45 Correct 1 ms 344 KB Output is correct
46 Partially correct 111 ms 424 KB Output is partially correct
47 Partially correct 95 ms 428 KB Output is partially correct
48 Partially correct 104 ms 684 KB Output is partially correct