#include <bits/stdc++.h>
#include "insects.h"
#define pb push_back
using namespace std;
//#include "../debug.h"
#define debug(x...) void(42)
constexpr static int BLOCK = 50;
int n;
set<int> basis;
bool check(int val)
{
vector<int> ci;
for (int i = 0; i < n; i++)
{
if (basis.find(i) != basis.end())
continue;
move_inside(i);
ci.pb(i);
if (press_button() > val)
{
ci.pop_back();
move_outside(i);
}
}
bool res = ci.size() == (val - 1) * basis.size();
for (int i : ci)
move_outside(i);
return res;
}
int test_a()
{
int l = 1, r = 1 + (n / basis.size());
debug(l, r);
while (r - l > 1)
{
int m = l+r>>1;
debug(m);
if(check(m))
l = m;
else
r = m;
}
debug(l);
return l;
}
vector<int> bs;
set<int> machine;
int get_min(int l, int r, vector<int>& v)
{
if (r - l == 1)
{
debug(l, v);
return v.size()+1;
}
int m = l+r>>1;
for (int i = l; i < m; i++)
{
if (machine.find(bs[i]) != machine.end())
continue;
machine.insert(bs[i]);
move_inside(bs[i]);
}
for (int i = m; i < r; i++)
{
if (machine.find(bs[i]) == machine.end())
continue;
machine.erase(bs[i]);
move_outside(bs[i]);
}
vector<int> lv, rv;
for (int i : v)
{
move_inside(i);
if (press_button() > 1)
lv.pb(i);
else
rv.pb(i);
move_outside(i);
}
int lres = get_min(l, m, lv);
int rres = get_min(m, r, rv);
return min(lres, rres);
}
int test_b()
{
for (int i : basis)
{
bs.pb(i);
machine.insert(i);
}
vector<int> v;
for (int i = 0; i < n; i++)
if (basis.find(i) == basis.end())
v.pb(i);
return get_min(0, bs.size(), v);
}
int min_cardinality(int N)
{
n = N;
for (int i = 0; i < n; i++)
{
move_inside(i);
if (press_button() > 1)
move_outside(i);
else
basis.insert(i);
}
if (basis.size() > BLOCK)
return test_a();
else
return test_b();
}
Compilation message
insects.cpp: In function 'int test_a()':
insects.cpp:41:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int m = l+r>>1;
| ~^~
insects.cpp: In function 'int get_min(int, int, std::vector<int>&)':
insects.cpp:61:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
300 KB |
Output is correct |
9 |
Correct |
6 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
7 ms |
208 KB |
Output is correct |
15 |
Correct |
6 ms |
304 KB |
Output is correct |
16 |
Correct |
6 ms |
300 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
208 KB |
Output is correct |
19 |
Correct |
8 ms |
208 KB |
Output is correct |
20 |
Correct |
9 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
300 KB |
Output is correct |
9 |
Correct |
6 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
300 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
208 KB |
Output is correct |
14 |
Correct |
7 ms |
208 KB |
Output is correct |
15 |
Correct |
6 ms |
304 KB |
Output is correct |
16 |
Correct |
6 ms |
300 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
7 ms |
208 KB |
Output is correct |
19 |
Correct |
8 ms |
208 KB |
Output is correct |
20 |
Correct |
9 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
296 KB |
Output is correct |
23 |
Correct |
7 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
320 KB |
Output is correct |
25 |
Correct |
38 ms |
208 KB |
Output is correct |
26 |
Correct |
36 ms |
300 KB |
Output is correct |
27 |
Correct |
18 ms |
292 KB |
Output is correct |
28 |
Correct |
8 ms |
300 KB |
Output is correct |
29 |
Correct |
21 ms |
292 KB |
Output is correct |
30 |
Correct |
37 ms |
292 KB |
Output is correct |
31 |
Correct |
30 ms |
300 KB |
Output is correct |
32 |
Correct |
26 ms |
208 KB |
Output is correct |
33 |
Correct |
32 ms |
304 KB |
Output is correct |
34 |
Correct |
31 ms |
296 KB |
Output is correct |
35 |
Correct |
34 ms |
320 KB |
Output is correct |
36 |
Correct |
36 ms |
208 KB |
Output is correct |
37 |
Correct |
40 ms |
280 KB |
Output is correct |
38 |
Correct |
29 ms |
208 KB |
Output is correct |
39 |
Correct |
15 ms |
208 KB |
Output is correct |
40 |
Correct |
9 ms |
316 KB |
Output is correct |
41 |
Correct |
9 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
17 ms |
276 KB |
Output is correct |
8 |
Correct |
14 ms |
336 KB |
Output is correct |
9 |
Partially correct |
92 ms |
292 KB |
Output is partially correct |
10 |
Partially correct |
49 ms |
304 KB |
Output is partially correct |
11 |
Correct |
27 ms |
292 KB |
Output is correct |
12 |
Correct |
16 ms |
320 KB |
Output is correct |
13 |
Partially correct |
41 ms |
288 KB |
Output is partially correct |
14 |
Partially correct |
74 ms |
304 KB |
Output is partially correct |
15 |
Partially correct |
45 ms |
208 KB |
Output is partially correct |
16 |
Partially correct |
28 ms |
292 KB |
Output is partially correct |
17 |
Partially correct |
40 ms |
288 KB |
Output is partially correct |
18 |
Partially correct |
82 ms |
292 KB |
Output is partially correct |
19 |
Partially correct |
66 ms |
296 KB |
Output is partially correct |
20 |
Partially correct |
73 ms |
288 KB |
Output is partially correct |
21 |
Partially correct |
47 ms |
304 KB |
Output is partially correct |
22 |
Partially correct |
49 ms |
456 KB |
Output is partially correct |
23 |
Partially correct |
62 ms |
288 KB |
Output is partially correct |
24 |
Correct |
37 ms |
316 KB |
Output is correct |
25 |
Correct |
20 ms |
324 KB |
Output is correct |
26 |
Correct |
17 ms |
340 KB |
Output is correct |
27 |
Partially correct |
75 ms |
296 KB |
Output is partially correct |
28 |
Partially correct |
93 ms |
296 KB |
Output is partially correct |
29 |
Partially correct |
70 ms |
292 KB |
Output is partially correct |
30 |
Partially correct |
79 ms |
304 KB |
Output is partially correct |
31 |
Partially correct |
87 ms |
300 KB |
Output is partially correct |
32 |
Partially correct |
85 ms |
208 KB |
Output is partially correct |
33 |
Partially correct |
86 ms |
208 KB |
Output is partially correct |
34 |
Partially correct |
70 ms |
280 KB |
Output is partially correct |
35 |
Partially correct |
92 ms |
300 KB |
Output is partially correct |
36 |
Partially correct |
85 ms |
324 KB |
Output is partially correct |
37 |
Partially correct |
75 ms |
300 KB |
Output is partially correct |
38 |
Partially correct |
82 ms |
300 KB |
Output is partially correct |
39 |
Partially correct |
59 ms |
304 KB |
Output is partially correct |
40 |
Partially correct |
71 ms |
296 KB |
Output is partially correct |
41 |
Partially correct |
60 ms |
296 KB |
Output is partially correct |
42 |
Partially correct |
81 ms |
280 KB |
Output is partially correct |
43 |
Partially correct |
18 ms |
308 KB |
Output is partially correct |
44 |
Partially correct |
49 ms |
284 KB |
Output is partially correct |
45 |
Correct |
30 ms |
276 KB |
Output is correct |
46 |
Correct |
17 ms |
316 KB |
Output is correct |
47 |
Correct |
26 ms |
336 KB |
Output is correct |
48 |
Correct |
24 ms |
300 KB |
Output is correct |