#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define rev(x, i) for (int i = (int)x - 1; i >= 0; i--)
#define ALL(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
int min_cardinality(int N)
{
vi ix(N);
iota(ALL(ix), 0);
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(ix.begin(), ix.end(), g);
vvi S(N);
int iter = 1;
S[0].pb(0);
move_inside(ix[0]);
for (int i = 1; i < N; i++)
{
move_inside(ix[i]);
int res = press_button();
if (res == 2)
{
move_outside(ix[i]);
S[1].pb(i);
}
else
S[0].pb(i);
}
int t = sz(S[0]);
if (t == 1)
return N;
while (sz(S[iter]))
{
if (sz(S[iter]) < t)
return iter;
int curSize = 1;
for (int i : S[iter - 1])
move_outside(ix[i]);
move_inside(ix[S[iter][0]]);
vi newCurS = {S[iter][0]};
for (int s_ix = 1; s_ix < sz(S[iter]); s_ix++)
{
int i = S[iter][s_ix];
move_inside(ix[i]);
int res = press_button();
if (res == 2)
{
move_outside(ix[i]);
S[iter + 1].pb(i);
}
else
{
curSize++;
newCurS.pb(i);
}
if (curSize == t)
{
for (int s_ix2 = s_ix + 1; s_ix2 < sz(S[iter]); s_ix2++)
{
int i2 = S[iter][s_ix2];
S[iter + 1].pb(i2);
}
break;
}
}
if (curSize < t)
return iter;
S[iter] = newCurS;
iter++;
}
return iter;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
452 KB |
Output is correct |
9 |
Correct |
4 ms |
452 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
344 KB |
Output is correct |
19 |
Correct |
3 ms |
448 KB |
Output is correct |
20 |
Correct |
4 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
452 KB |
Output is correct |
9 |
Correct |
4 ms |
452 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
344 KB |
Output is correct |
19 |
Correct |
3 ms |
448 KB |
Output is correct |
20 |
Correct |
4 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
40 ms |
744 KB |
Output is correct |
26 |
Correct |
35 ms |
756 KB |
Output is correct |
27 |
Correct |
9 ms |
472 KB |
Output is correct |
28 |
Correct |
8 ms |
728 KB |
Output is correct |
29 |
Correct |
18 ms |
708 KB |
Output is correct |
30 |
Correct |
10 ms |
344 KB |
Output is correct |
31 |
Correct |
76 ms |
1164 KB |
Output is correct |
32 |
Correct |
69 ms |
1200 KB |
Output is correct |
33 |
Correct |
60 ms |
1164 KB |
Output is correct |
34 |
Correct |
43 ms |
896 KB |
Output is correct |
35 |
Correct |
53 ms |
800 KB |
Output is correct |
36 |
Correct |
59 ms |
760 KB |
Output is correct |
37 |
Correct |
25 ms |
600 KB |
Output is correct |
38 |
Correct |
15 ms |
480 KB |
Output is correct |
39 |
Correct |
11 ms |
472 KB |
Output is correct |
40 |
Correct |
12 ms |
600 KB |
Output is correct |
41 |
Correct |
7 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
504 KB |
Output is correct |
8 |
Correct |
11 ms |
344 KB |
Output is correct |
9 |
Partially correct |
83 ms |
1032 KB |
Output is partially correct |
10 |
Partially correct |
114 ms |
896 KB |
Output is partially correct |
11 |
Correct |
27 ms |
600 KB |
Output is correct |
12 |
Correct |
17 ms |
616 KB |
Output is correct |
13 |
Correct |
29 ms |
500 KB |
Output is correct |
14 |
Correct |
24 ms |
520 KB |
Output is correct |
15 |
Partially correct |
222 ms |
2940 KB |
Output is partially correct |
16 |
Partially correct |
172 ms |
1832 KB |
Output is partially correct |
17 |
Partially correct |
207 ms |
1860 KB |
Output is partially correct |
18 |
Partially correct |
164 ms |
2212 KB |
Output is partially correct |
19 |
Partially correct |
132 ms |
1400 KB |
Output is partially correct |
20 |
Partially correct |
152 ms |
1272 KB |
Output is partially correct |
21 |
Partially correct |
85 ms |
868 KB |
Output is partially correct |
22 |
Partially correct |
60 ms |
760 KB |
Output is partially correct |
23 |
Correct |
24 ms |
516 KB |
Output is correct |
24 |
Correct |
23 ms |
344 KB |
Output is correct |
25 |
Correct |
13 ms |
596 KB |
Output is correct |
26 |
Correct |
13 ms |
344 KB |
Output is correct |
27 |
Partially correct |
68 ms |
836 KB |
Output is partially correct |
28 |
Partially correct |
81 ms |
876 KB |
Output is partially correct |
29 |
Partially correct |
89 ms |
748 KB |
Output is partially correct |
30 |
Partially correct |
112 ms |
1412 KB |
Output is partially correct |
31 |
Partially correct |
67 ms |
504 KB |
Output is partially correct |
32 |
Partially correct |
56 ms |
600 KB |
Output is partially correct |
33 |
Correct |
29 ms |
500 KB |
Output is correct |
34 |
Correct |
32 ms |
592 KB |
Output is correct |
35 |
Partially correct |
90 ms |
924 KB |
Output is partially correct |
36 |
Partially correct |
86 ms |
756 KB |
Output is partially correct |
37 |
Partially correct |
90 ms |
860 KB |
Output is partially correct |
38 |
Partially correct |
94 ms |
840 KB |
Output is partially correct |
39 |
Partially correct |
55 ms |
624 KB |
Output is partially correct |
40 |
Partially correct |
63 ms |
1104 KB |
Output is partially correct |
41 |
Partially correct |
70 ms |
1112 KB |
Output is partially correct |
42 |
Partially correct |
82 ms |
1124 KB |
Output is partially correct |
43 |
Correct |
5 ms |
344 KB |
Output is correct |
44 |
Correct |
21 ms |
740 KB |
Output is correct |
45 |
Partially correct |
128 ms |
5944 KB |
Output is partially correct |
46 |
Correct |
11 ms |
344 KB |
Output is correct |
47 |
Correct |
17 ms |
600 KB |
Output is correct |
48 |
Correct |
12 ms |
344 KB |
Output is correct |