답안 #859327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859327 2023-10-10T04:12:17 Z kim 드문 곤충 (IOI22_insects) C++17
99.89 / 100
42 ms 1740 KB
#include "insects.h"
#include<bits/stdc++.h>

using namespace std;

#define in move_inside
#define press press_button
#define out move_outside

set<int> mp,mp2,mp3;
int n,p,k0;
bool flag[2005];

bool check(int k1){
    stack<int> st,st3;
    for(int i=0;i<n;++i){
        if(flag[i]) continue;
        if(mp.count(i)) continue;
        if(mp3.count(i)) continue;
        in(i);
        if(press()>k1) out(i),st3.push(i);
        else mp.insert(i),st.push(i);
    }
    if(mp.size()==p*k1){
        k0=k1;
        for(auto &e:mp) if(mp2.count(e)) mp2.erase(e);
        return 1;
    }
    while(!st3.empty()){
        flag[st3.top()]=1;
        st3.pop();
    }
    stack<int> st2;
    for(auto &e:mp2){
        if(!mp.count(e)) st2.push(e);
    }
    while(!st2.empty()){
        mp2.erase(st2.top());
        mp3.insert(st2.top());
        st2.pop();
    }
    while(st.size()){
        mp.erase(st.top());
        out(st.top());
        st.pop();
    }
    return 0;
}

int min_cardinality(int N){
    n=N;
    for(int i=0;i<n;++i){
        in(i);
        if(press()>1) out(i),mp2.insert(i);
        else mp.insert(i);
    }
    p=mp.size();
    k0=1;

    int l=1,r=n/p;
    while(l<r){
        int mid=l+(r-l+1>>1);
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    return l;
}

Compilation message

insects.cpp: In function 'bool check(int)':
insects.cpp:24:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |     if(mp.size()==p*k1){
      |        ~~~~~~~~~^~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:62:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |         int mid=l+(r-l+1>>1);
      |                    ~~~^~
# 결과 실행 시간 메모리 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 0 ms 344 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 3 ms 440 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 448 KB Output is correct
22 Correct 1 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 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 3 ms 440 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 448 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 17 ms 1368 KB Output is correct
24 Correct 4 ms 856 KB Output is correct
25 Correct 13 ms 1368 KB Output is correct
26 Correct 15 ms 852 KB Output is correct
27 Correct 11 ms 1388 KB Output is correct
28 Correct 5 ms 1112 KB Output is correct
29 Correct 13 ms 856 KB Output is correct
30 Correct 13 ms 600 KB Output is correct
31 Correct 12 ms 856 KB Output is correct
32 Correct 15 ms 960 KB Output is correct
33 Correct 16 ms 856 KB Output is correct
34 Correct 15 ms 1740 KB Output is correct
35 Correct 18 ms 600 KB Output is correct
36 Correct 18 ms 1116 KB Output is correct
37 Correct 12 ms 628 KB Output is correct
38 Correct 14 ms 956 KB Output is correct
39 Correct 13 ms 856 KB Output is correct
40 Correct 9 ms 600 KB Output is correct
41 Correct 4 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 0 ms 344 KB Output is correct
7 Correct 32 ms 808 KB Output is correct
8 Correct 8 ms 1124 KB Output is correct
9 Correct 26 ms 1720 KB Output is correct
10 Correct 23 ms 1140 KB Output is correct
11 Correct 25 ms 1396 KB Output is correct
12 Correct 15 ms 1248 KB Output is correct
13 Correct 28 ms 1664 KB Output is correct
14 Correct 27 ms 1484 KB Output is correct
15 Correct 31 ms 1520 KB Output is correct
16 Correct 28 ms 1132 KB Output is correct
17 Correct 31 ms 1184 KB Output is correct
18 Correct 29 ms 956 KB Output is correct
19 Partially correct 32 ms 992 KB Output is partially correct
20 Correct 36 ms 1256 KB Output is correct
21 Correct 31 ms 1148 KB Output is correct
22 Correct 31 ms 1244 KB Output is correct
23 Correct 26 ms 976 KB Output is correct
24 Correct 21 ms 796 KB Output is correct
25 Correct 18 ms 1368 KB Output is correct
26 Correct 8 ms 1368 KB Output is correct
27 Correct 27 ms 964 KB Output is correct
28 Correct 35 ms 856 KB Output is correct
29 Partially correct 32 ms 1376 KB Output is partially correct
30 Partially correct 28 ms 1616 KB Output is partially correct
31 Correct 42 ms 724 KB Output is correct
32 Correct 29 ms 1216 KB Output is correct
33 Correct 25 ms 1656 KB Output is correct
34 Correct 27 ms 1112 KB Output is correct
35 Partially correct 35 ms 1368 KB Output is partially correct
36 Partially correct 31 ms 600 KB Output is partially correct
37 Correct 25 ms 1012 KB Output is correct
38 Correct 28 ms 972 KB Output is correct
39 Correct 36 ms 1412 KB Output is correct
40 Correct 27 ms 1368 KB Output is correct
41 Partially correct 26 ms 916 KB Output is partially correct
42 Partially correct 31 ms 1220 KB Output is partially correct
43 Correct 7 ms 856 KB Output is correct
44 Correct 20 ms 1372 KB Output is correct
45 Correct 32 ms 1164 KB Output is correct
46 Correct 16 ms 988 KB Output is correct
47 Correct 15 ms 1368 KB Output is correct
48 Correct 13 ms 900 KB Output is correct