This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
int min_cardinality(int N) {
vector<int> idx_type;
idx_type.push_back(0);
move_inside(0);
bool check1 = false;
for(int i = 1;i<N;i++) {
move_inside(i);
int val=press_button();
if(val == 2){
move_outside(i);
check1=true;
}
else idx_type.push_back(i);
}
if(!check1)return N;
for(int i:idx_type) {
move_outside(i);
}
vector<int> l(N, -1), r(N, idx_type.size()-1);
for(int i = 0;i<idx_type.size();i++) {
r[idx_type[i]]=i;
l[idx_type[i]]=i-1;
}
vector<pair<int,int>> que;
int tmp=0;
for(int i = 0;i<N;i++) {
if(r[i]!=i)r[i]=upper_bound(idx_type.begin(), idx_type.end(), i)-idx_type.begin()-1;
}
while(1) {
que.clear();
bool check=false;
for(int i = 0;i<N;i++) {
if(r[i]-l[i]<=1)continue;
que.push_back({(r[i]+l[i])/2, i});
check=true;
}
int cnt=tmp;
sort(que.begin(), que.end());
for(int i = 0;i<que.size();i++) {
int mid = que[i].first;
while(cnt > mid+1) {
move_outside(idx_type[--cnt]);
}
while(cnt <= mid) {
move_inside(idx_type[cnt++]);
}
move_inside(que[i].second);
int val=press_button();
if(val == 2) {
r[que[i].second]=que[i].first;
}
else {
l[que[i].second]=que[i].first;
}
move_outside(que[i].second);
}
tmp=cnt;
if(!check)break;
}
vector<int> cnt(N+1, 0);
for(int i = 0;i<N;i++) {
cnt[idx_type[r[i]]]++;
}
int ans=20000;
for(int i = 0;i<N;i++) {
if(cnt[i]==0)continue;
ans=min(ans, cnt[i]);
}
return ans;
}
Compilation message (stderr)
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i = 0;i<idx_type.size();i++) {
| ~^~~~~~~~~~~~~~~~
insects.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0;i<que.size();i++) {
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |