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<bits/stdc++.h>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
int min_cardinality(int n) {
mt19937 gen(22);
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
shuffle(ord.begin(), ord.end(), gen);
vector<int> used(n);
for (auto i : ord) {
move_inside(i);
if (press_button() >= 2) {
move_outside(i);
} else {
used[i] = 1;
}
}
int cnt = accumulate(used.begin(), used.end(), 0);
if (cnt == 1) {
return n;
}
int l = 1, r = n / cnt + 1;
auto start = used;
vector<int> ban(n);
while (l + 1 < r) {
int m = (l + r) / 2;
for (auto i : ord) {
if (used[i] && !start[i]) {
used[i] = 0;
move_outside(i);
}
}
vector<int> b;
int cnt2 = accumulate(used.begin(), used.end(), 0);
for (auto i : ord) {
if (!used[i] && !ban[i]) {
move_inside(i);
int res = press_button();
if (res >= m + 1) {
move_outside(i);
b.push_back(i);
} else {
used[i] = 1;
cnt2++;
if (cnt2 == m * cnt) {
break;
}
}
}
}
//cout << m << " " << cnt2 << endl;
//for (auto x : used) cout << x << " "; cout << endl;
//for (auto x : ban) cout << x << " "; cout << endl;
if (m * cnt == cnt2) {
l = m;
start = used;
} else {
r = m;
for (auto i : b) {
ban[i] = 1;
}
}
}
return l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |