이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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);
| ~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |