답안 #851833

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851833 2023-09-20T16:58:45 Z kh0i 드문 곤충 (IOI22_insects) C++17
100 / 100
35 ms 1948 KB
#include <bits/stdc++.h>

#include "insects.h"
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

set<int> inside;
map<int, set<int>> states;
int D = 0;
vector<int> a;

void move_in(int x){
    if(inside.count(x)) return;
    move_inside(a[x]);
    inside.insert(x);
}

void move_out(int x){
    if(!inside.count(x)) return;
    move_outside(a[x]);
    inside.erase(x);
}

int min_cardinality(int N) {
    a.resize(N);
    iota(a.begin(), a.end(), 0);
    shuffle(a.begin(), a.end(), rng);

    for (int i = 0; i < N; ++i) {
        D += 1;
        move_in(i);
        if (press_button() > 1) {
            move_out(i);
            D -= 1;
        }
    }
    states[1] = inside;
    for(int i = 0 ; i < N; ++i) states[N].insert(i);
    // clear
    for (int i = 0; i < N; ++i)
        move_out(i);

    // N log N
    int l = 1, r = N / D, ans = 1;
    while (l <= r) {
        int mid = (l + r) / 2;
        vector<int> last_inserted;
        auto it = *states.lower_bound(mid);
        for (int i : it.second) {
            if ((int)inside.size() >= mid * D) break;
            if (!inside.count(i)) {
                move_in(i);
                if (press_button() > mid)
                    move_out(i); 
                else
                    last_inserted.push_back(i);
            }
        }
        cerr << "(cnt = " << inside.size() << ", mid = " << mid << ", d = " << D << ")\n";
        states[mid] = inside;
        if ((int)inside.size() >= mid * D) {
            l = mid + 1;
            ans = mid;
        } else {
            r = mid - 1;
            for(int i : last_inserted) move_out(i);
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 3 ms 856 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
14 Correct 3 ms 1112 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 3 ms 696 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 3 ms 856 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
14 Correct 3 ms 1112 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 3 ms 696 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 14 ms 1484 KB Output is correct
24 Correct 11 ms 856 KB Output is correct
25 Correct 16 ms 1456 KB Output is correct
26 Correct 13 ms 1488 KB Output is correct
27 Correct 12 ms 856 KB Output is correct
28 Correct 7 ms 864 KB Output is correct
29 Correct 12 ms 856 KB Output is correct
30 Correct 14 ms 1104 KB Output is correct
31 Correct 13 ms 1200 KB Output is correct
32 Correct 12 ms 976 KB Output is correct
33 Correct 13 ms 1240 KB Output is correct
34 Correct 15 ms 1236 KB Output is correct
35 Correct 14 ms 1304 KB Output is correct
36 Correct 13 ms 1112 KB Output is correct
37 Correct 15 ms 1008 KB Output is correct
38 Correct 15 ms 948 KB Output is correct
39 Correct 13 ms 1372 KB Output is correct
40 Correct 10 ms 1112 KB Output is correct
41 Correct 9 ms 1220 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 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 26 ms 1820 KB Output is correct
8 Correct 19 ms 1708 KB Output is correct
9 Correct 25 ms 1592 KB Output is correct
10 Correct 32 ms 1516 KB Output is correct
11 Correct 27 ms 640 KB Output is correct
12 Correct 18 ms 1524 KB Output is correct
13 Correct 35 ms 1104 KB Output is correct
14 Correct 29 ms 1412 KB Output is correct
15 Correct 24 ms 1936 KB Output is correct
16 Correct 25 ms 1576 KB Output is correct
17 Correct 25 ms 1584 KB Output is correct
18 Correct 23 ms 1244 KB Output is correct
19 Correct 30 ms 1700 KB Output is correct
20 Correct 23 ms 1352 KB Output is correct
21 Correct 31 ms 1948 KB Output is correct
22 Correct 26 ms 1468 KB Output is correct
23 Correct 28 ms 928 KB Output is correct
24 Correct 22 ms 968 KB Output is correct
25 Correct 21 ms 1408 KB Output is correct
26 Correct 16 ms 1376 KB Output is correct
27 Correct 31 ms 1492 KB Output is correct
28 Correct 25 ms 1580 KB Output is correct
29 Correct 31 ms 1512 KB Output is correct
30 Correct 25 ms 1540 KB Output is correct
31 Correct 32 ms 1224 KB Output is correct
32 Correct 32 ms 1872 KB Output is correct
33 Correct 27 ms 1056 KB Output is correct
34 Correct 28 ms 848 KB Output is correct
35 Correct 26 ms 1088 KB Output is correct
36 Correct 29 ms 1360 KB Output is correct
37 Correct 32 ms 1552 KB Output is correct
38 Correct 32 ms 1720 KB Output is correct
39 Correct 32 ms 1200 KB Output is correct
40 Correct 29 ms 1224 KB Output is correct
41 Correct 27 ms 1224 KB Output is correct
42 Correct 24 ms 1372 KB Output is correct
43 Correct 8 ms 504 KB Output is correct
44 Correct 22 ms 1364 KB Output is correct
45 Correct 26 ms 1760 KB Output is correct
46 Correct 18 ms 1780 KB Output is correct
47 Correct 26 ms 1460 KB Output is correct
48 Correct 21 ms 1468 KB Output is correct