이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
// en el primer for los meto todos y intento identificar los que son iguales al primero
// y los primeros (si el max es 1 y despues de añadir sigue siendo 1, es un primero)
// quiero saber cuanto vale max
shuffle(all(v), rng);
mx = 1;
int extra = 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);
mx = press_button();
if (ok && mx == i+1) {
tp[x] = 0;
extra++;
}
else {
ok = 0;
if (mx == 1) {
tp[x] = tp[f.back()]+1;
f.push_back(x);
}
}
}
// quito los no primeros
int curr = 0;
for (int i = 0; i < n; i++) {
int x = v[i];
if (curr < (int)f.size() && f[curr] == x) {
curr++;
continue;
}
move_outside(x);
}
// primer for y ver cuantos son iguales al primero
shuffle(all(v), rng);
for (int i = 0; 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;
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... |