답안 #859437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859437 2023-10-10T07:20:09 Z kim 드문 곤충 (IOI22_insects) C++17
0 / 100
0 ms 596 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;
 
bool check(int k1){
    stack<int> st;
    for(int i=0;i<n;++i){
        if(mp.size()==p*k1) break;
        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){
        for(auto &e:mp) if(mp2.count(e)) mp2.erase(e);
        return 1;
    }
    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();
 
    int l=1,r=(n-1)/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:16:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |         if(mp.size()==p*k1) break;
      |            ~~~~~~~~~^~~~~~
insects.cpp:23:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |     if(mp.size()==p*k1){
      |        ~~~~~~~~~^~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:55:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |         int mid=l+(r-l+1>>1);
      |                    ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong answer.
3 Halted 0 ms 0 KB -