#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int tc, n, ra = 0;
vi M, IS, U;
void mi(int i) {
if(U[IS[i]]) move_inside(IS[i]);
M.push_back(IS[i]);
}
void mo(int i = 0) {
if(U[IS[i]]) move_outside(M.back());
M.pop_back();
}
int pb() {
return press_button()+ra;
}
bool tjek(int g) {
int ctr = n;
//while(M.size() > 1) mo();
for(int i = 0; i < n; i++) {
mi(i);
if(pb() > g) ctr--, mo(i);
}
if(ctr == g*tc) {
for(auto x : M)
move_outside(x), U[x] = 0;
ra += g;
return 1;
}
else {
return 0;
}
}
int min_cardinality(int N) {
tc = n = N;
IS.resize(n);
for(int i = 0; i < n; i++) IS[i] = i;
srand(time(NULL));
random_shuffle(IS.begin(), IS.end());
U.resize(n, 1);
mi(0);
for(int i = 1; i < n; i++) {
mi(i);
if(pb() > 1) tc--, mo(i);
}
for(auto x : M)
U[x] = 0, move_outside(x);
ra += 1;
int l = 1, u = n/tc;
while(l < u) {
int g = (l+u+1)/2;
if(tjek(g)) l = g;
else u = g-1;
}
return l;
}
/*
11
1 3 3 7 1 3 5 7 5 1 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Incorrect |
12 ms |
344 KB |
Wrong answer. |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Incorrect |
12 ms |
344 KB |
Wrong answer. |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Wrong answer. |
7 |
Halted |
0 ms |
0 KB |
- |