#include "insects.h"
#ifdef NYAOWO
#include "stub.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
int find_types(vector<int> &sus) {
vector<int> rep;
vector<int> uwu;
for(auto &i:sus) {
move_inside(i);
if(press_button() == 1) {
rep.eb(i);
} else {
move_outside(i);
uwu.eb(i);
}
}
sus = uwu;
// for(auto &i:rep) move_outside(i);
return sz(rep);
}
// # of all types >= k ?
bool check(int k, int m, vector<int> &sus, int good) {
if(sz(sus) + good < k * m) return false;
// for(auto &i:sus) cerr << i << " ";
vector<int> owo;
vector<int> uwu;
for(auto &i:sus) {
move_inside(i);
if(press_button() > k) {
uwu.eb(i);
move_outside(i);
} else {
owo.eb(i);
}
}
// cerr << " - " << k << " " << sz(owo) + good << " " << (m * k == sz(owo) + good) << "\n";
if(m * k == sz(owo) + good) {
sus = uwu;
return true;
}
sus = owo;
for(auto &i:owo) move_outside(i);
return false;
}
int min_cardinality(int n) {
vector<int> sus;
For(i, 0, n - 1) sus.eb(i);
random_shuffle(all(sus));
int m = find_types(sus);
cerr << m << "\n";
int ans = 1;
while(sz(sus)) {
int lo = 1;
while(check(ans + lo, m, sus, ans * m)) {
ans += lo; lo *= 2;
}
}
return ans;
}
/*
6
5 8 9 5 9 9
1
7
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Execution timed out |
3054 ms |
208 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Execution timed out |
3054 ms |
208 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3062 ms |
208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |