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;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>V, usun, Q;
int n, m;
int solve(int l, int r, vector<int>czy) {
if(l==r) return l;
int mid=(l+r+1)/2;
vector<int>A, B;
rep(i, n) if(czy[i]) {
move_inside(Q[i]);
++m;
if(press_button()>mid) {
A.pb(i);
move_outside(Q[i]);
--m;
} else B.pb(i);
if(m==mid*V.size()) break;
}
if(m==mid*V.size()) {
for(auto i : B) czy[i]=0;
return solve(mid, r, czy);
}
for(auto i : A) czy[i]=0;
for(auto i : B) {
move_outside(Q[i]);
--m;
}
return solve(l, mid-1, czy);
}
int min_cardinality(int _n) {
n=_n;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
rep(i, n) {
Q.pb(i);
swap(Q[i], Q[rng()%(i+1)]);
}
rep(i, n) {
++m;
move_inside(Q[i]);
if(press_button()==1) V.pb(i);
else {
move_outside(Q[i]);
--m;
}
}
vector<int>czy(n, 1);
for(auto i : V) czy[i]=0;
rep(i, V.size()) usun.pb(0);
return solve(1, n/V.size(), czy);
}
Compilation message (stderr)
insects.cpp: In function 'int solve(int, int, std::vector<int>)':
insects.cpp:23:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(m==mid*V.size()) break;
| ~^~~~~~~~~~~~~~
insects.cpp:25:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(m==mid*V.size()) {
| ~^~~~~~~~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
insects.cpp:54:2: note: in expansion of macro 'rep'
54 | rep(i, V.size()) usun.pb(0);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |