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 <iostream>
#include <vector>
#define ll long long
using namespace std;
int min_cardinality(int N) {
vector <ll> V, X, A, B;
ll s = 0, a, b, mid, f = 1;
for (int i=0; i<N; ++i) {
move_inside(i);
auto res = press_button();
if (res > 1) {
move_outside(i);
X.push_back(i);
}
else V.push_back(i);
}
for (auto u : V) move_outside(u);
s = V.size();
while (true) {
A.clear();
B.clear();
if (X.size() < s) return f;
a = (X.size() / s) / 2;
a = max(a, 1LL);
b = a+1;
b = min(b, (ll)X.size()/s);
if (abs(a*s-(ll)X.size()/2) > abs(b*s-(ll)X.size()/2)) mid = b;
else mid = a;
ll p = -1;
for (auto u : X) {
move_inside(u);
auto res = press_button();
if (res == mid && p == -1) p = u;
if (res > mid) {
B.push_back(u);
move_outside(u);
}
else A.push_back(u);
}
for (auto u : A) move_outside(u);
if (A.size() == mid * s) {
swap(X, B);
f += mid;
}
else {
swap(X, A);
for (int i=0; i<X.size(); ++i) {
if (X[i] == p) {
swap(X[i], X.back());
X.pop_back();
break;
}
}
}
}
}
Compilation message (stderr)
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:25:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
25 | if (X.size() < s) return f;
| ~~~~~~~~~^~~
insects.cpp:44:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
44 | if (A.size() == mid * s) {
| ~~~~~~~~~^~~~~~~~~~
insects.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i=0; i<X.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... |