답안 #628146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628146 2022-08-13T06:26:17 Z qwerasdfzxcl 드문 곤충 (IOI22_insects) C++17
100 / 100
63 ms 552 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
mt19937 rng(1557);
vector<int> P;
set<int> qst, cd;
int n, t;

bool ins(int x){
    bool ret = qst.insert(x).second;
    if (ret) move_inside(P[x-1]);
    return ret;
}

bool del(int x){
    if (qst.find(x)==qst.end()) return 0;
    qst.erase(x);
    move_outside(P[x-1]);
    return 1;
}

void get_type(){
    for (int i=1;i<=n;i++){
        ins(i);
        if (press_button()>1) del(i);
    }

    t = qst.size();
    for (int i=1;i<=n;i++) if (qst.find(i)==qst.end()) cd.insert(i);
}

bool ok(int c){
    if (cd.empty()){
        return (int)qst.size() == t*c;
    }

    if (qst.find(*cd.begin())!=qst.end()){
        for (auto &x:cd) del(x);
    }

    for (auto &x:cd){
        ins(x);
        if (press_button()>c) del(x);
        if ((int)qst.size() == t*c) break;
    }

    bool ret = (int)qst.size() == t*c;
    for (auto iter=cd.begin();iter!=cd.end();){
        if ((qst.find(*iter)!=qst.end())==ret) iter = cd.erase(iter);
        else iter++;
    }

    return ret;
}

int min_cardinality(int N) {
    for (int i=0;i<N;i++) P.push_back(i);
    shuffle(P.begin(), P.end(), rng);
    n = N;
    get_type();
    if (t==1) return n;

    int l = 2, r = N / t, ans = 1;
    while(l<=r){
        int m = (l+r)>>1;
        if (ok(m)) l = m+1, ans = m;
        else r = m-1;
    }
    return ans;
}
# 결과 실행 시간 메모리 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 304 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 3 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 4 ms 336 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 8 ms 208 KB Output is correct
20 Correct 5 ms 308 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 3 ms 308 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 304 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 3 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 4 ms 336 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 8 ms 208 KB Output is correct
20 Correct 5 ms 308 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 3 ms 308 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 9 ms 312 KB Output is correct
25 Correct 18 ms 300 KB Output is correct
26 Correct 30 ms 352 KB Output is correct
27 Correct 15 ms 312 KB Output is correct
28 Correct 12 ms 324 KB Output is correct
29 Correct 23 ms 312 KB Output is correct
30 Correct 24 ms 328 KB Output is correct
31 Correct 18 ms 304 KB Output is correct
32 Correct 22 ms 304 KB Output is correct
33 Correct 17 ms 340 KB Output is correct
34 Correct 18 ms 392 KB Output is correct
35 Correct 20 ms 360 KB Output is correct
36 Correct 19 ms 308 KB Output is correct
37 Correct 21 ms 312 KB Output is correct
38 Correct 22 ms 352 KB Output is correct
39 Correct 21 ms 348 KB Output is correct
40 Correct 12 ms 320 KB Output is correct
41 Correct 8 ms 336 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 0 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 17 ms 308 KB Output is correct
8 Correct 11 ms 348 KB Output is correct
9 Correct 52 ms 416 KB Output is correct
10 Correct 36 ms 432 KB Output is correct
11 Correct 42 ms 292 KB Output is correct
12 Correct 30 ms 332 KB Output is correct
13 Correct 63 ms 296 KB Output is correct
14 Correct 44 ms 308 KB Output is correct
15 Correct 46 ms 420 KB Output is correct
16 Correct 47 ms 552 KB Output is correct
17 Correct 60 ms 416 KB Output is correct
18 Correct 42 ms 456 KB Output is correct
19 Correct 38 ms 432 KB Output is correct
20 Correct 55 ms 304 KB Output is correct
21 Correct 26 ms 328 KB Output is correct
22 Correct 58 ms 428 KB Output is correct
23 Correct 45 ms 312 KB Output is correct
24 Correct 44 ms 328 KB Output is correct
25 Correct 40 ms 336 KB Output is correct
26 Correct 21 ms 356 KB Output is correct
27 Correct 38 ms 308 KB Output is correct
28 Correct 52 ms 308 KB Output is correct
29 Correct 36 ms 400 KB Output is correct
30 Correct 42 ms 328 KB Output is correct
31 Correct 50 ms 312 KB Output is correct
32 Correct 52 ms 304 KB Output is correct
33 Correct 48 ms 428 KB Output is correct
34 Correct 47 ms 424 KB Output is correct
35 Correct 49 ms 420 KB Output is correct
36 Correct 35 ms 416 KB Output is correct
37 Correct 57 ms 328 KB Output is correct
38 Correct 48 ms 424 KB Output is correct
39 Correct 56 ms 428 KB Output is correct
40 Correct 43 ms 312 KB Output is correct
41 Correct 41 ms 312 KB Output is correct
42 Correct 44 ms 408 KB Output is correct
43 Correct 15 ms 308 KB Output is correct
44 Correct 21 ms 336 KB Output is correct
45 Correct 45 ms 424 KB Output is correct
46 Correct 32 ms 324 KB Output is correct
47 Correct 33 ms 320 KB Output is correct
48 Correct 20 ms 328 KB Output is correct