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 all(x) x.begin(), x.end()
const int N = 2e3+3, inf = INT_MAX;
mt19937 rng((chrono::steady_clock::now().time_since_epoch().count()) + ((uint64_t) new char));
int n, mx, ans, tp[N];
vector<int> v, f;
int min_cardinality(int N) {
// move_inside(i);
// move_outside(i);
// press_button(i);
memset(tp, -1, sizeof(tp));
ans = inf;
n = N;
v.resize(n);
for (int i = 0; i < n; i++) v[i] = i;
// quiero saber cuanto vale max
shuffle(all(v), rng);
int mxPressed = -1;
int extra = 0;
mx = 0;
bool ok = 1;
move_inside(v[0]);
f.push_back(v[0]);
tp[v[0]] = 0;
for (int i = 1; i < n; i++) {
int x = v[i];
move_inside(x);
if (ok) {
mxPressed = i;
mx = press_button();
if (mx == i+1) {
tp[x] = 0;
extra++;
}
}
else {
ok = 0;
}
}
if (mxPressed < n-1) mx = press_button();
for (int i = 1; i < n; i++) {
int x = v[i];
move_outside(x); // dejo al 0 dentro
}
//cerr << mx << endl;
// primer for y ver cuantos son iguales al primero
for (int i = 1; i < n; i++) {
int x = v[i];
if (tp[x] != -1) continue;
move_inside(x);
if (press_button() > 1) {
move_outside(x);
}
else {
tp[x] = tp[f.back()]+1;
f.push_back(x);
}
}
// miro cada grupo
for (int t = 0; t < (int)f.size(); t++) {
shuffle(all(v), rng);
if (t) extra = 0;
int curr = 1; // cuantos he metido?
vector<int> added;
for (int i = 0; i < n && curr+extra < mx; i++) {
int x = v[i];
if (tp[x] != -1) continue;
move_inside(x);
if (press_button() == curr+1) {
tp[x] = t;
added.push_back(x);
curr++;
}
else {
move_outside(x);
}
}
for (int& x : added) {
move_outside(x);
}
ans = min(ans, curr+extra);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |