#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int n, tc, il, rc = 0;
set<int> M, IU;
vi IS;
void mi(int i) {
move_inside(IS[i]);
M.insert(i);
}
void mo(int i) {
move_outside(IS[i]);
M.erase(i);
}
int pb() {
return press_button()+rc;
}
void rm(bool t) {
if(t) {
for(auto x : M) {
IU.erase(x);
move_outside(IS[x]);
}
il -= M.size();
rc += M.size()/tc;
M.clear();
}
else {
IU = M;
il = M.size();
for(auto x : M)
move_outside(IS[x]);
M.clear();
}
}
bool tjek(int g) {
for(auto i : IU) {
mi(i);
if(pb() > g) mo(i);
}
bool s = (int(M.size())+rc*tc == tc*g);
rm(s);
return s;
}
int min_cardinality(int N) {
il = n = N;
IS.resize(n);
for(int i = 0; i < n; i++)
IS[i] = i;
srand(time(NULL));
random_shuffle(IS.begin(), IS.end());
mi(0);
for(int i = 1; i < n; i++) {
mi(i);
if(pb() > 1) mo(i);
}
tc = M.size();
for(int i = 0; i < n; i++)
IU.insert(i);
rm(1);
int l = 1, u = n/tc;
while(l < u) {
int mx = -1, g = (l+u+1)/2;
for(int i = l; i <= u; i++) {
if(max(tc*i, il-tc*i+1) > mx)
mx = max(tc*i, il-tc*i+1), g = i;
}
if(tjek(g)) l = g;
else u = g-1;
}
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
436 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
20 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
12 ms |
436 KB |
Output is correct |
13 |
Correct |
8 ms |
344 KB |
Output is correct |
14 |
Correct |
8 ms |
436 KB |
Output is correct |
15 |
Correct |
5 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
7 ms |
436 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
4 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
436 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
20 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
12 ms |
436 KB |
Output is correct |
13 |
Correct |
8 ms |
344 KB |
Output is correct |
14 |
Correct |
8 ms |
436 KB |
Output is correct |
15 |
Correct |
5 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
7 ms |
436 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
4 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
10 ms |
344 KB |
Output is correct |
24 |
Correct |
7 ms |
440 KB |
Output is correct |
25 |
Correct |
8 ms |
436 KB |
Output is correct |
26 |
Correct |
61 ms |
600 KB |
Output is correct |
27 |
Incorrect |
238 ms |
344 KB |
Too many queries. |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
13 ms |
444 KB |
Output is correct |
8 |
Correct |
9 ms |
456 KB |
Output is correct |
9 |
Correct |
22 ms |
588 KB |
Output is correct |
10 |
Partially correct |
218 ms |
1052 KB |
Output is partially correct |
11 |
Incorrect |
259 ms |
1052 KB |
Too many queries. |
12 |
Halted |
0 ms |
0 KB |
- |