답안 #1076852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076852 2024-08-26T17:19:11 Z Zicrus 드문 곤충 (IOI22_insects) C++17
54.04 / 100
154 ms 1012 KB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
 
typedef long long ll;
 
int n;
vector<bool> in;
unordered_set<int> sIn, sOut;
int cnt;
int numA, numP;

mt19937 mt;
 
void add(int i) {
    if (in[i]) return;
    numA++;
    move_inside(i);
    cnt++;
    in[i] = true;
}

int add_rand() {
    int id = mt() % sOut.size();
    auto iter = sOut.begin();
    while (id--) iter++;
    int i = *iter;
    add(i);
    sOut.erase(i);
    return i;
}

void remove(int i) {
    if (!in[i]) return;
    move_outside(i);
    cnt--;
    in[i] = false;
}

int remove_rand() {
    int id = mt() % sIn.size();
    auto iter = sIn.begin();
    while (id--) iter++;
    int i = *iter;
    remove(i);
    sIn.erase(i);
    return i;
}

int press() {
    numP++;
    return press_button();
}
 
int min_cardinality(int N) {
    n = N;
    cnt = 0;
    numA = numP = 0;
    mt = mt19937(time(0));
    in = vector<bool>(n);
    int cur = 0;
    
    for (int i = 0; i < n; i++) {
        add(i);
        cur = press();
        if (cur > 1) {
            remove(i);
            sOut.insert(i);
            cur = 1;
        }
    }
    int typeCnt = cnt;
    
    int left = 1, right = n / typeCnt;
    bool up = true;
    restart:
    while (left < right) {
        int mid = (left + right + 1) / 2;

        unordered_set<int> later;
        try_up:
        if (up) {
            while (cnt < typeCnt * mid) {
                if (sOut.empty()) {
                    right = mid - 1;
                    up = false;
                    for (auto &e : later) sOut.insert(e);
                    later.clear();
                    goto restart;
                }
                
                int inc = mid - cur + 1;
                int recent = -1;
                while (!sOut.empty() && inc--) {
                    recent = add_rand();
                    sIn.insert(recent);
                }
                cur = press();
                if (cur > mid) {
                    remove(recent);
                    sIn.erase(recent);
                    later.insert(recent);
                    cur = mid;
                }
            }
            left = mid;
            up = true;
            sIn.clear();
            for (auto &e : later) sOut.insert(e);
            later.clear();
        }
        else {
            while (cur > mid) {
                int dec = cur - mid + 1;
                int recent = -1;
                while (dec--) {
                    recent = remove_rand();
                    sOut.insert(recent);
                }
                cur = press();
                if (cur < mid) {
                    add(recent);
                    sOut.erase(recent);
                    later.insert(recent);
                    cur = mid;
                }
            }
            up = true;
            for (auto &e : later) sIn.insert(e);
            later.clear();
            goto try_up;
        }
    }

    return left;
} 
 
#ifdef TEST
#include "grader.cpp"
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 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 2 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 6 ms 460 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 456 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 4 ms 448 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 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 2 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 6 ms 460 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 456 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 4 ms 448 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 22 ms 600 KB Output is correct
27 Correct 71 ms 724 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
29 Correct 56 ms 760 KB Output is correct
30 Correct 29 ms 344 KB Output is correct
31 Correct 8 ms 480 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 13 ms 696 KB Output is correct
34 Correct 11 ms 344 KB Output is correct
35 Correct 11 ms 440 KB Output is correct
36 Correct 18 ms 856 KB Output is correct
37 Correct 13 ms 600 KB Output is correct
38 Correct 19 ms 480 KB Output is correct
39 Correct 13 ms 456 KB Output is correct
40 Correct 10 ms 344 KB Output is correct
41 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 14 ms 488 KB Output is correct
8 Correct 13 ms 344 KB Output is correct
9 Correct 18 ms 540 KB Output is correct
10 Partially correct 42 ms 596 KB Output is partially correct
11 Partially correct 142 ms 828 KB Output is partially correct
12 Correct 12 ms 460 KB Output is correct
13 Partially correct 154 ms 1012 KB Output is partially correct
14 Partially correct 92 ms 616 KB Output is partially correct
15 Correct 16 ms 344 KB Output is correct
16 Correct 24 ms 600 KB Output is correct
17 Correct 18 ms 600 KB Output is correct
18 Correct 26 ms 516 KB Output is correct
19 Correct 27 ms 476 KB Output is correct
20 Correct 33 ms 696 KB Output is correct
21 Partially correct 35 ms 600 KB Output is partially correct
22 Partially correct 58 ms 600 KB Output is partially correct
23 Partially correct 51 ms 764 KB Output is partially correct
24 Correct 26 ms 784 KB Output is correct
25 Correct 19 ms 856 KB Output is correct
26 Correct 10 ms 600 KB Output is correct
27 Correct 26 ms 848 KB Output is correct
28 Correct 32 ms 600 KB Output is correct
29 Correct 16 ms 484 KB Output is correct
30 Correct 23 ms 596 KB Output is correct
31 Partially correct 51 ms 600 KB Output is partially correct
32 Partially correct 50 ms 516 KB Output is partially correct
33 Partially correct 60 ms 812 KB Output is partially correct
34 Partially correct 56 ms 600 KB Output is partially correct
35 Correct 21 ms 512 KB Output is correct
36 Correct 20 ms 728 KB Output is correct
37 Partially correct 33 ms 500 KB Output is partially correct
38 Partially correct 45 ms 732 KB Output is partially correct
39 Correct 31 ms 704 KB Output is correct
40 Correct 28 ms 500 KB Output is correct
41 Correct 35 ms 856 KB Output is correct
42 Correct 24 ms 496 KB Output is correct
43 Partially correct 19 ms 504 KB Output is partially correct
44 Partially correct 110 ms 768 KB Output is partially correct
45 Correct 18 ms 720 KB Output is correct
46 Correct 25 ms 940 KB Output is correct
47 Correct 16 ms 472 KB Output is correct
48 Correct 10 ms 464 KB Output is correct