#include <cassert>
#include <cstdio>
#include <insects.h>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
#define vi vector<int>
#include <random>
/*
int kMaxQueries = 40000;
static int N;
// Insect types are compressed to colors in the range [0, N).
static std::vector<int> color;
static std::vector<bool> in_box;
static std::vector<int> color_occurrences;
static std::multiset<int> max_occurrences;
static std::vector<int> op_counter(3, 0);
static inline void protocol_violation(std::string message) {
printf("Protocol Violation: %s\n", message.c_str());
exit(0);
}
void move_inside(int i) {
if (i < 0 || i >= N) {
protocol_violation("invalid parameter");
}
++op_counter[0];
if (op_counter[0] > kMaxQueries) {
protocol_violation("too many calls");
}
if (!in_box[i]) {
in_box[i] = true;
max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
++color_occurrences[color[i]];
max_occurrences.insert(color_occurrences[color[i]]);
}
}
void move_outside(int i) {
if (i < 0 || i >= N) {
protocol_violation("invalid parameter");
}
++op_counter[1];
if (op_counter[1] > kMaxQueries) {
protocol_violation("too many calls");
}
if (in_box[i]) {
in_box[i] = false;
max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
--color_occurrences[color[i]];
max_occurrences.insert(color_occurrences[color[i]]);
}
}
int press_button() {
++op_counter[2];
if (op_counter[2] > kMaxQueries) {
protocol_violation("too many calls");
}
return *(max_occurrences.rbegin());
}
*/
int min_cardinality(int N) {
int sum = 0;
vector<bool> in(N);
for (int i = 0; i < N; i++) {
move_inside(i);
sum++;
in[i] = 1;
if (press_button() > 1) {
move_outside(i);
sum--;
in[i] = 0;
}
}
const int n = N;
const int num = sum;
//int cur = 1;
int s = 1, e = N / num;
vi col_siz(N);
vi my_col(N, -1);
vi good;
for (int i = 0; i < n; i++)if (in[i])good.push_back(i);
if (1==0) {
}
else {
while (s != e) {
int mid = (s+e+1) / 2;
vi ne;
for (int i = 0; i < n; i++) {
if (!in[i]) {
move_inside(i);
if (press_button() > mid) {
move_outside(i);
}
else {
in[i] = 1;
ne.push_back(i);
sum++;
}
}
if (sum == mid * num)break;
if (sum + n - i - 1 < mid * num)break;
}
if (sum == mid * num) {
s = mid;
}
else {
e = mid - 1;
for (int x : ne) {
move_outside(x);
sum--;
in[x] = 0;
}
}
}
return s;
}
}
Compilation message
insects.cpp:9: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
9 | #pragma warning(disable : 4996)
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
800 KB |
Output is correct |
10 |
Correct |
6 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
600 KB |
Output is correct |
18 |
Correct |
4 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
800 KB |
Output is correct |
10 |
Correct |
6 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
600 KB |
Output is correct |
18 |
Correct |
4 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
9 ms |
600 KB |
Output is correct |
24 |
Correct |
4 ms |
496 KB |
Output is correct |
25 |
Correct |
11 ms |
600 KB |
Output is correct |
26 |
Correct |
22 ms |
344 KB |
Output is correct |
27 |
Correct |
48 ms |
600 KB |
Output is correct |
28 |
Correct |
6 ms |
600 KB |
Output is correct |
29 |
Correct |
37 ms |
600 KB |
Output is correct |
30 |
Correct |
28 ms |
600 KB |
Output is correct |
31 |
Correct |
11 ms |
600 KB |
Output is correct |
32 |
Correct |
11 ms |
600 KB |
Output is correct |
33 |
Correct |
16 ms |
600 KB |
Output is correct |
34 |
Correct |
14 ms |
600 KB |
Output is correct |
35 |
Correct |
10 ms |
344 KB |
Output is correct |
36 |
Correct |
16 ms |
344 KB |
Output is correct |
37 |
Correct |
16 ms |
344 KB |
Output is correct |
38 |
Correct |
15 ms |
600 KB |
Output is correct |
39 |
Correct |
14 ms |
600 KB |
Output is correct |
40 |
Correct |
7 ms |
600 KB |
Output is correct |
41 |
Correct |
4 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
512 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 |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
19 ms |
848 KB |
Output is correct |
8 |
Correct |
11 ms |
400 KB |
Output is correct |
9 |
Correct |
21 ms |
848 KB |
Output is correct |
10 |
Partially correct |
34 ms |
848 KB |
Output is partially correct |
11 |
Partially correct |
88 ms |
600 KB |
Output is partially correct |
12 |
Correct |
11 ms |
344 KB |
Output is correct |
13 |
Partially correct |
101 ms |
412 KB |
Output is partially correct |
14 |
Partially correct |
66 ms |
612 KB |
Output is partially correct |
15 |
Correct |
21 ms |
668 KB |
Output is correct |
16 |
Correct |
25 ms |
420 KB |
Output is correct |
17 |
Correct |
33 ms |
420 KB |
Output is correct |
18 |
Correct |
27 ms |
608 KB |
Output is correct |
19 |
Correct |
26 ms |
612 KB |
Output is correct |
20 |
Partially correct |
26 ms |
600 KB |
Output is partially correct |
21 |
Partially correct |
38 ms |
652 KB |
Output is partially correct |
22 |
Partially correct |
39 ms |
856 KB |
Output is partially correct |
23 |
Partially correct |
37 ms |
428 KB |
Output is partially correct |
24 |
Correct |
26 ms |
660 KB |
Output is correct |
25 |
Correct |
13 ms |
416 KB |
Output is correct |
26 |
Correct |
9 ms |
600 KB |
Output is correct |
27 |
Correct |
31 ms |
424 KB |
Output is correct |
28 |
Correct |
18 ms |
600 KB |
Output is correct |
29 |
Correct |
26 ms |
412 KB |
Output is correct |
30 |
Correct |
25 ms |
848 KB |
Output is correct |
31 |
Partially correct |
37 ms |
856 KB |
Output is partially correct |
32 |
Partially correct |
35 ms |
420 KB |
Output is partially correct |
33 |
Partially correct |
53 ms |
600 KB |
Output is partially correct |
34 |
Partially correct |
48 ms |
412 KB |
Output is partially correct |
35 |
Partially correct |
29 ms |
848 KB |
Output is partially correct |
36 |
Correct |
27 ms |
656 KB |
Output is correct |
37 |
Partially correct |
44 ms |
928 KB |
Output is partially correct |
38 |
Partially correct |
39 ms |
848 KB |
Output is partially correct |
39 |
Correct |
29 ms |
608 KB |
Output is correct |
40 |
Correct |
18 ms |
608 KB |
Output is correct |
41 |
Correct |
25 ms |
592 KB |
Output is correct |
42 |
Partially correct |
34 ms |
400 KB |
Output is partially correct |
43 |
Partially correct |
14 ms |
600 KB |
Output is partially correct |
44 |
Partially correct |
79 ms |
848 KB |
Output is partially correct |
45 |
Correct |
28 ms |
592 KB |
Output is correct |
46 |
Correct |
15 ms |
600 KB |
Output is correct |
47 |
Correct |
9 ms |
600 KB |
Output is correct |
48 |
Correct |
13 ms |
592 KB |
Output is correct |