QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#143317 | #4565. Rarest Insects | bashkort | 0 | 5ms | 3828kb | C++20 | 4.0kb | 2023-08-21 02:46:49 | 2023-08-21 02:46:52 |
answer
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 rnd(1337);
void razmeshay(vector<int> &a) {
for (int t = 0; t < 3; ++t) {
for (int i = 0; i < size(a); ++i) {
swap(a[i], a[rnd() % size(a)]);
}
}
}
int min_cardinality(int N) {
vector<int> a(N);
iota(a.begin(), a.end(), 0);
razmeshay(a);
vector<int> leaders, inside(N);
int maxSize = 0, T = 0, cntIn = 0, lastQueryT = 0;
int queriesCnt[3]{};
auto insert = [&](int x) -> bool {
if (inside[x]) {
return false;
}
cntIn += 1;
move_inside(x);
T += 1;
queriesCnt[0] += 1;
return inside[x] = true;
};
auto erase = [&](int x) -> void {
if (!inside[x]) {
return;
}
cntIn -= 1;
move_outside(x);
T += 1;
queriesCnt[1] += 1;
inside[x] = false;
};
auto query = [&]() -> int {
if (T == lastQueryT) {
return maxSize;
}
lastQueryT = T;
queriesCnt[2] += 1;
return maxSize = press_button();
};
vector<int> others;
for (int x : a) {
insert(x);
if (query() == 1) {
leaders.push_back(x);
} else {
others.push_back(x);
erase(x);
}
};
int ans = N;
if (size(leaders) > size(others)) {
return 1;
} else if (size(leaders) == 1) {
return N;
}
if (0) {
shuffle(leaders.begin(), leaders.end(), rnd);
auto dfs = [&](auto dfs, vector<int> lead, vector<int> oth, int isFull) -> void {
if (ans == 1) {
return;
}
if (size(lead) == 1) {
ans = min<int>(ans, 1 + size(oth));
return;
}
if (size(lead) > size(oth)) {
ans = 1;
return;
}
int mid = size(lead) / 2;
vector<int> leadLeft(lead.begin(), lead.begin() + mid);
vector<int> leadRight(lead.begin() + mid, lead.end());
vector<int> nxt[2];
if (isFull) {
for (int x: leadRight) {
erase(x);
}
} else {
for (int x: leadLeft) {
insert(x);
}
}
for (int x: oth) {
insert(x);
if (query() == 1) {
nxt[1].push_back(x);
} else {
nxt[0].push_back(x);
}
erase(x);
}
dfs(dfs, leadLeft, nxt[0], true);
dfs(dfs, leadRight, nxt[1], false);
};
dfs(dfs, leaders, others, true);
return ans;
} else {
shuffle(others.begin(), others.end(), rnd);
razmeshay(others);
int k = 4, i, cnt;
for (k = 2, i = 0, cnt = 0; cnt < size(others) && k * size(leaders) <= N; i = i + 1 == size(others) ? 0 : i + 1) {
if (insert(others[i])) {
if (query() > k) {
erase(others[i]);
} else {
if (size(leaders) * k == cntIn) {
k += 2;
cnt = 0;
}
}
}
cnt += 1;
}
k = max(k - 3, 2);
for (i = 0, cnt = 0; cnt < size(others) && k * size(leaders) <= N; i = i + 1 == size(others) ? 0 : i + 1) {
if (insert(others[i])) {
if (query() > k) {
erase(others[i]);
} else {
if (size(leaders) * k == cntIn) {
k += 1;
cnt = 0;
}
}
}
cnt += 1;
}
return k - 1;
}
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 2ms
memory: 3704kb
input:
6 1 2 1 2 1 2 2 2 3 3
output:
8 0 5 8 2 8 0 4 8 2 8 1 4 8 0 0 8 2 8 0 2 8 2 8 1 2 8 0 1 8 2 8 0 3 8 2 8 1 3 8 0 2 8 2 8 0 3 8 2 8 0 4 8 2 8 1 4 8 0 4 8 2 8 1 4 8 3 1
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
2 1 2
output:
8 0 1 8 2 8 0 0 8 2 8 1 0 8 3 2
result:
ok
Test #3:
score: 0
Accepted
time: 2ms
memory: 3696kb
input:
2 1 1
output:
8 0 1 8 2 8 0 0 8 2 8 3 1
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3764kb
input:
3 1 1 2
output:
8 0 1 8 2 8 0 0 8 2 8 0 2 8 2 8 1 2 8 3 1
result:
ok
Test #5:
score: -10
Wrong Answer
time: 2ms
memory: 3696kb
input:
5 1 1 2 2 2 2 2 3
output:
8 0 1 8 2 8 0 3 8 2 8 0 4 8 2 8 1 4 8 0 2 8 2 8 1 2 8 0 0 8 2 8 1 0 8 0 2 8 2 8 0 0 8 2 8 0 4 8 2 8 1 4 8 3 1
result:
wrong answer Wrong answer.
Subtask #2:
score: 0
Wrong Answer
Test #24:
score: 15
Accepted
time: 2ms
memory: 3716kb
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 147 8 2 8 0 505 8 2 8 1 505 8 0 814 8 2 8 1 814 8 0 310 8 2 8 1 310 8 0 571 8 2 8 1 571 8 0 301 8 2 8 1 301 8 0 137 8 2 8 1 137 8 0 930 8 2 8 1 930 8 0 136 8 2 8 1 136 8 0 129 8 2 8 1 129 8 0 323 8 2 8 1 323 8 0 340 8 2 8 1 340 8 0 397 8 2 8 1 397 8 0 630 8 2 8 1 630 8 0 101 8 2 8 1 101 8 0 769 ...
result:
ok
Test #25:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
8 0 147 8 2 8 0 505 8 2 8 0 814 8 2 8 0 310 8 2 8 0 571 8 2 8 0 301 8 2 8 0 137 8 2 8 0 930 8 2 8 0 136 8 2 8 0 129 8 2 8 0 323 8 2 8 0 340 8 2 8 0 397 8 2 8 0 630 8 2 8 0 101 8 2 8 0 769 8 2 8 0 219 8 2 8 0 635 8 2 8 0 560 8 2 8 0 118 8 2 8 0 20 8 2 8 0 254 8 2 8 0 665 8 2 8 0 693 8 2 8 0 673 8 2 8...
result:
ok
Test #26:
score: -15
Wrong Answer
time: 5ms
memory: 3792kb
input:
999 1 1 1 1 1 1 2 1 1 2 1 2 1 1 2 2 1 1 1 2 2 2 1 1 1 2 2 1 2 2 1 2 1 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 2 1 2 2 2 2 2 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 1 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 1 2 2 2 2 2 ...
output:
8 0 612 8 2 8 0 68 8 2 8 0 772 8 2 8 0 865 8 2 8 0 419 8 2 8 0 812 8 2 8 0 414 8 2 8 1 414 8 0 27 8 2 8 0 606 8 2 8 0 876 8 2 8 1 876 8 0 524 8 2 8 0 168 8 2 8 1 168 8 0 21 8 2 8 0 660 8 2 8 0 721 8 2 8 1 721 8 0 842 8 2 8 1 842 8 0 299 8 2 8 0 869 8 2 8 0 618 8 2 8 0 750 8 2 8 1 750 8 0 849 8 2 8 1...
result:
wrong answer Wrong answer.
Subtask #3:
score: 0
Wrong Answer
Test #43:
score: 75
Accepted
time: 0ms
memory: 3704kb
input:
2 1 2
output:
8 0 1 8 2 8 0 0 8 2 8 1 0 8 3 2
result:
ok
Test #44:
score: 75
Accepted
time: 2ms
memory: 3812kb
input:
2 1 1
output:
8 0 1 8 2 8 0 0 8 2 8 3 1
result:
ok
Test #45:
score: 75
Accepted
time: 0ms
memory: 3764kb
input:
3 1 1 2
output:
8 0 1 8 2 8 0 0 8 2 8 0 2 8 2 8 1 2 8 3 1
result:
ok
Test #46:
score: 75
Accepted
time: 1ms
memory: 3692kb
input:
6 1 2 2 1 2 2 2 3 3 3 3 3 3
output:
8 0 5 8 2 8 0 4 8 2 8 1 4 8 0 0 8 2 8 1 0 8 0 2 8 2 8 0 1 8 2 8 1 1 8 0 3 8 2 8 1 3 8 0 3 8 2 8 0 1 8 2 8 1 1 8 0 0 8 2 8 1 0 8 0 4 8 2 8 1 4 8 0 1 8 2 8 1 1 8 0 0 8 2 8 1 0 8 0 4 8 2 8 1 4 8 3 1
result:
ok
Test #47:
score: 0
Wrong Answer
time: 2ms
memory: 3700kb
input:
10 1 2 2 2 1 2 2 2 2 2 2 2 3 3 4 5 5 4 5 5
output:
8 0 8 8 2 8 0 6 8 2 8 1 6 8 0 9 8 2 8 1 9 8 0 5 8 2 8 1 5 8 0 1 8 2 8 0 7 8 2 8 1 7 8 0 4 8 2 8 1 4 8 0 2 8 2 8 1 2 8 0 0 8 2 8 1 0 8 0 3 8 2 8 1 3 8 0 3 8 2 8 0 5 8 2 8 0 9 8 2 8 0 7 8 2 8 0 4 8 2 8 0 6 8 2 8 1 6 8 0 0 8 2 8 1 0 8 0 2 8 2 8 0 6 8 2 8 1 6 8 0 0 8 2 8 1 0 8 3 2
result:
wrong answer Wrong answer.