#include "insects.h"
#include <vector>
#include <random>
#include <algorithm>
#include <set>
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
const int C = 4;
int min_cardinality(int n) {
vector<int> v;
v.push_back(0);
move_inside(0);
for(int i = 1; i < n; ++i){
move_inside(i);
if(press_button() == 2){
move_outside(i);
}
else
v.push_back(i);
}
for(int x: v)
move_outside(x);
vector<int> type(n);
int k = v.size();
if(k <= C){
vector<bool> in_v(n, false);
for(int x: v)
in_v[x] = true;
for(int i = 0; (1 << i) < k; ++i){
for(int j = 0; j < k; ++j){
if((j >> i) & 1){
type[v[j]] += (1 << i);
move_inside(v[j]);
}
}
for(int j = 0; j < n; ++j){
if(in_v[j]) continue;
move_inside(j);
if(press_button() == 2)
type[j] += (1 << i);
move_outside(j);
}
for(int j = 0; j < k; ++j){
if((j >> i) & 1){
move_outside(v[j]);
}
}
}
vector<int> cnt(k);
for(int i = 0; i < n; ++i)
cnt[type[i]]++;
return *min_element(cnt.begin(), cnt.end());
}
vector<int> rem;
for(int i = 0; i < n; ++i){
if(find(v.begin(), v.end(), i) == v.end())
rem.push_back(i);
}
mt19937 mt(6);
int ans = 1;
while(!rem.empty()){
if(rem.size() < k)
return ans;
v.clear();
shuffle(rem.begin(), rem.end(), mt);
move_inside(rem[0]);
v.push_back(rem[0]);
for(int i = 1; i < rem.size(); ++i){
int x = rem[i];
move_inside(x);
if(press_button() == 1){
v.push_back(x);
if(v.size() == k)
break;
}
else{
move_outside(x);
}
}
for(int x: v)
move_outside(x);
if(v.size() < k)
return ans;
++ans;
vector<int> rem2;
set<int> s;
for(int x: v)
s.insert(x);
for(int x: rem)
if(!s.count(x))
rem2.push_back(x);
swap(rem, rem2);
}
return ans;
}
Compilation message
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:76:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
76 | if(rem.size() < k)
| ~~~~~~~~~~~^~~
insects.cpp:83:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i = 1; i < rem.size(); ++i){
| ~~^~~~~~~~~~~~
insects.cpp:88:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
88 | if(v.size() == k)
| ~~~~~~~~~^~~~
insects.cpp:97:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
97 | if(v.size() < k)
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
288 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
236 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
10 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
292 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 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 |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
288 KB |
Output is correct |
8 |
Correct |
5 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
236 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
10 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
292 KB |
Output is correct |
17 |
Correct |
4 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
336 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
208 KB |
Output is correct |
23 |
Correct |
9 ms |
288 KB |
Output is correct |
24 |
Correct |
10 ms |
288 KB |
Output is correct |
25 |
Correct |
43 ms |
208 KB |
Output is correct |
26 |
Correct |
20 ms |
208 KB |
Output is correct |
27 |
Correct |
16 ms |
208 KB |
Output is correct |
28 |
Correct |
11 ms |
288 KB |
Output is correct |
29 |
Correct |
25 ms |
280 KB |
Output is correct |
30 |
Correct |
17 ms |
272 KB |
Output is correct |
31 |
Correct |
34 ms |
268 KB |
Output is correct |
32 |
Correct |
36 ms |
272 KB |
Output is correct |
33 |
Correct |
32 ms |
280 KB |
Output is correct |
34 |
Correct |
34 ms |
288 KB |
Output is correct |
35 |
Correct |
30 ms |
292 KB |
Output is correct |
36 |
Correct |
39 ms |
288 KB |
Output is correct |
37 |
Correct |
43 ms |
208 KB |
Output is correct |
38 |
Correct |
36 ms |
288 KB |
Output is correct |
39 |
Correct |
18 ms |
292 KB |
Output is correct |
40 |
Correct |
12 ms |
208 KB |
Output is correct |
41 |
Correct |
10 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
16 ms |
208 KB |
Output is correct |
8 |
Correct |
14 ms |
296 KB |
Output is correct |
9 |
Partially correct |
85 ms |
284 KB |
Output is partially correct |
10 |
Partially correct |
82 ms |
284 KB |
Output is partially correct |
11 |
Correct |
36 ms |
328 KB |
Output is correct |
12 |
Correct |
24 ms |
292 KB |
Output is correct |
13 |
Correct |
45 ms |
280 KB |
Output is correct |
14 |
Correct |
30 ms |
268 KB |
Output is correct |
15 |
Partially correct |
67 ms |
208 KB |
Output is partially correct |
16 |
Partially correct |
50 ms |
272 KB |
Output is partially correct |
17 |
Partially correct |
92 ms |
272 KB |
Output is partially correct |
18 |
Partially correct |
72 ms |
280 KB |
Output is partially correct |
19 |
Partially correct |
80 ms |
268 KB |
Output is partially correct |
20 |
Partially correct |
43 ms |
208 KB |
Output is partially correct |
21 |
Partially correct |
81 ms |
208 KB |
Output is partially correct |
22 |
Partially correct |
75 ms |
272 KB |
Output is partially correct |
23 |
Correct |
39 ms |
272 KB |
Output is correct |
24 |
Correct |
16 ms |
296 KB |
Output is correct |
25 |
Correct |
26 ms |
288 KB |
Output is correct |
26 |
Correct |
17 ms |
276 KB |
Output is correct |
27 |
Partially correct |
82 ms |
272 KB |
Output is partially correct |
28 |
Partially correct |
94 ms |
280 KB |
Output is partially correct |
29 |
Partially correct |
71 ms |
268 KB |
Output is partially correct |
30 |
Partially correct |
96 ms |
292 KB |
Output is partially correct |
31 |
Partially correct |
71 ms |
272 KB |
Output is partially correct |
32 |
Partially correct |
67 ms |
208 KB |
Output is partially correct |
33 |
Correct |
40 ms |
296 KB |
Output is correct |
34 |
Correct |
56 ms |
280 KB |
Output is correct |
35 |
Partially correct |
62 ms |
284 KB |
Output is partially correct |
36 |
Partially correct |
82 ms |
272 KB |
Output is partially correct |
37 |
Partially correct |
41 ms |
284 KB |
Output is partially correct |
38 |
Partially correct |
87 ms |
280 KB |
Output is partially correct |
39 |
Partially correct |
91 ms |
280 KB |
Output is partially correct |
40 |
Partially correct |
87 ms |
296 KB |
Output is partially correct |
41 |
Partially correct |
98 ms |
280 KB |
Output is partially correct |
42 |
Partially correct |
83 ms |
328 KB |
Output is partially correct |
43 |
Correct |
12 ms |
288 KB |
Output is correct |
44 |
Correct |
27 ms |
208 KB |
Output is correct |
45 |
Correct |
31 ms |
268 KB |
Output is correct |
46 |
Correct |
15 ms |
296 KB |
Output is correct |
47 |
Correct |
28 ms |
208 KB |
Output is correct |
48 |
Correct |
28 ms |
208 KB |
Output is correct |