QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398107 | #4565. Rarest Insects | hos_lyric | 0 | 1ms | 3860kb | C++14 | 968b | 2024-04-24 22:14:40 | 2024-04-24 22:14:40 |
answer
#include "insects.h"
#include <vector>
using std::vector;
#define push move_inside
#define pop move_outside
#define get press_button
// us -> vs, ws
vector<int> us, vs, ws;
void go(int thr) {
vs.clear();
ws.clear();
for (const int u : us) {
push(u);
if (get() <= thr) {
vs.push_back(u);
} else {
pop(u);
ws.push_back(u);
}
}
}
#include <assert.h>
int min_cardinality(int N) {
us.resize(N);
for (int u = 0; u < N; ++u) us[u] = u;
go(1);
const int K = vs.size();
us.swap(ws);
assert(K >= 3);
// keep inside: lo insects of each type
int lo = 1, hi = N / K + 1;
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
go(mid);
if ((int)vs.size() >= K * (mid - lo)) {
lo = mid;
us.swap(ws);
} else {
hi = lo + (int)vs.size() / K + 1;
for (const int v : vs) pop(v);
us.swap(vs);
}
}
return lo;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 10
Accepted
time: 1ms
memory: 3860kb
input:
6 1 1 1 2 2 2 2 2 3
output:
8 0 0 8 2 8 0 1 8 2 8 0 2 8 2 8 0 3 8 2 8 1 3 8 0 4 8 2 8 1 4 8 0 5 8 2 8 1 5 8 0 3 8 2 8 0 4 8 2 8 0 5 8 2 8 1 5 8 1 3 8 1 4 8 3 1
result:
ok
Test #2:
score: 0
Runtime Error
input:
2 1 2
output:
8 0 0 8 2 8 0 1 8 2
result:
Subtask #2:
score: 0
Runtime Error
Test #24:
score: 0
Runtime Error
input:
1000 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
8 0 0 8 2 8 0 1 8 2 8 1 1 8 0 2 8 2 8 1 2 8 0 3 8 2 8 1 3 8 0 4 8 2 8 1 4 8 0 5 8 2 8 1 5 8 0 6 8 2 8 1 6 8 0 7 8 2 8 1 7 8 0 8 8 2 8 1 8 8 0 9 8 2 8 1 9 8 0 10 8 2 8 1 10 8 0 11 8 2 8 1 11 8 0 12 8 2 8 1 12 8 0 13 8 2 8 1 13 8 0 14 8 2 8 1 14 8 0 15 8 2 8 1 15 8 0 16 8 2 8 1 16 8 0 17 8 2 8 1 17 8 ...
result:
Subtask #3:
score: 0
Runtime Error
Test #43:
score: 0
Runtime Error
input:
2 1 2
output:
8 0 0 8 2 8 0 1 8 2