Submission #859312

# Submission time Handle Problem Language Result Execution time Memory
859312 2023-10-10T03:47:08 Z kim Rarest Insects (IOI22_insects) C++17
0 / 100
1 ms 344 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 check(int k1){
    stack<int> st;
    for(int i=0;i<n;++i){
        if(mp.count(i)) continue;
        if(mp3.count(i)) continue;
        in(i);
        if(press()>k1) out(i);
        else mp.insert(i),st.push(i);
    }
    if(mp.size()==p*k1){
        k0=k1;
        for(auto &e:mp) mp2.erase(e);
        return 1;
    }
    for(auto e:mp2){
        if(!mp.count(e)) mp3.insert(e),mp2.erase(e);
    }
    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;
    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:22:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     if(mp.size()==p*k1){
      |        ~~~~~~~~~^~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:50:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |         int mid=l+(r-l+1>>1);
      |                    ~~~^~
# Verdict Execution time Memory 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 Runtime error 1 ms 344 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Runtime error 1 ms 344 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -