Submission #978516

# Submission time Handle Problem Language Result Execution time Memory
978516 2024-05-09T09:25:27 Z Temmie Rarest Insects (IOI22_insects) C++17
99.89 / 100
1133 ms 20936 KB
#include "insects.h"

#include <bits/stdc++.h>

std::set <int> IN;

std::set <int> last;

void inside(int x) {
	IN.insert(x);
}

void outside(int x) {
	IN.erase(x);
}

int ask(int n) {
	for (int i = 0; i < n; i++) {
		if (IN.count(i) && !last.count(i)) {
			move_inside(i);
		} else if (!IN.count(i) && last.count(i)) {
			move_outside(i);
		}
	}
	static std::map <std::vector <int>, int> mem;
	last = IN;
	std::vector <int> tmp;
	for (int x : IN) tmp.push_back(x);
	auto it = mem.find(tmp);
	if (it != mem.end()) return it->second;
	return mem[tmp] = press_button();
}

std::vector <int> invert(std::vector <int> v, int n) {
	std::vector <int> u;
	std::sort(v.begin(), v.end());
	for (int i = 0, j = 0; i < n; i++) {
		if (j < (int) v.size() && v[j] == i) {
			j++;
			continue;
		}
		u.push_back(i);
	}
	return u;
}

int min_cardinality(int n) {
	std::vector <int> in, pool;
	for (int i = 0; i < n; i++) {
		inside(i);
		in.push_back(i);
		if (ask(n) == 1) continue;
		outside(i);
		in.pop_back();
		pool.push_back(i);
	}
	int uniq = in.size();
	int ans = 1;
	for (int l = 2, r = n / uniq; l <= r; ) {
		int mid = (l + r) >> 1;
		in.clear();
		std::vector <int> new_pool;
		for (int i : pool) {
			inside(i);
			in.push_back(i);
			if (ask(n) > mid) {
				outside(i);
				in.pop_back();
				new_pool.push_back(i);
				continue;
			}
		}
		pool = new_pool;
		if ((int) IN.size() == uniq * mid) {
			ans = mid;
			l = mid + 1;
		} else {
			r = mid - 1;
			pool = in;
			for (int x : in) {
				outside(x);
			}
		}
	}
	return ans;
}
# 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 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 7 ms 600 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 7 ms 1752 KB Output is correct
9 Correct 7 ms 620 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 6 ms 868 KB Output is correct
13 Correct 6 ms 1144 KB Output is correct
14 Correct 7 ms 764 KB Output is correct
15 Correct 7 ms 856 KB Output is correct
16 Correct 7 ms 952 KB Output is correct
17 Correct 6 ms 492 KB Output is correct
18 Correct 6 ms 856 KB Output is correct
19 Correct 6 ms 1112 KB Output is correct
20 Correct 6 ms 600 KB Output is correct
21 Correct 4 ms 664 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
# 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 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 7 ms 600 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 7 ms 1752 KB Output is correct
9 Correct 7 ms 620 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 6 ms 868 KB Output is correct
13 Correct 6 ms 1144 KB Output is correct
14 Correct 7 ms 764 KB Output is correct
15 Correct 7 ms 856 KB Output is correct
16 Correct 7 ms 952 KB Output is correct
17 Correct 6 ms 492 KB Output is correct
18 Correct 6 ms 856 KB Output is correct
19 Correct 6 ms 1112 KB Output is correct
20 Correct 6 ms 600 KB Output is correct
21 Correct 4 ms 664 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 217 ms 5208 KB Output is correct
24 Correct 99 ms 2924 KB Output is correct
25 Correct 220 ms 5412 KB Output is correct
26 Correct 211 ms 4880 KB Output is correct
27 Correct 67 ms 2180 KB Output is correct
28 Correct 58 ms 2196 KB Output is correct
29 Correct 100 ms 3004 KB Output is correct
30 Correct 121 ms 3612 KB Output is correct
31 Correct 225 ms 5800 KB Output is correct
32 Correct 230 ms 5220 KB Output is correct
33 Correct 220 ms 5144 KB Output is correct
34 Correct 220 ms 5476 KB Output is correct
35 Correct 217 ms 5208 KB Output is correct
36 Correct 209 ms 4968 KB Output is correct
37 Correct 215 ms 4812 KB Output is correct
38 Correct 127 ms 3344 KB Output is correct
39 Correct 129 ms 3488 KB Output is correct
40 Correct 132 ms 3896 KB Output is correct
41 Correct 78 ms 2320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 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 1025 ms 19720 KB Output is correct
8 Correct 417 ms 8936 KB Output is correct
9 Correct 1066 ms 19404 KB Output is correct
10 Correct 893 ms 15364 KB Output is correct
11 Correct 308 ms 5084 KB Output is correct
12 Correct 545 ms 8884 KB Output is correct
13 Correct 482 ms 7596 KB Output is correct
14 Correct 592 ms 9548 KB Output is correct
15 Correct 1044 ms 19220 KB Output is correct
16 Correct 1032 ms 19692 KB Output is correct
17 Correct 1033 ms 19172 KB Output is correct
18 Correct 1014 ms 18960 KB Output is correct
19 Partially correct 1050 ms 19520 KB Output is partially correct
20 Correct 1030 ms 18952 KB Output is correct
21 Correct 959 ms 16852 KB Output is correct
22 Correct 799 ms 13188 KB Output is correct
23 Correct 617 ms 10476 KB Output is correct
24 Correct 793 ms 13112 KB Output is correct
25 Correct 637 ms 11084 KB Output is correct
26 Correct 389 ms 7164 KB Output is correct
27 Correct 996 ms 18668 KB Output is correct
28 Correct 975 ms 18324 KB Output is correct
29 Partially correct 1061 ms 20448 KB Output is partially correct
30 Partially correct 1059 ms 19928 KB Output is partially correct
31 Correct 903 ms 14820 KB Output is correct
32 Correct 915 ms 16512 KB Output is correct
33 Correct 615 ms 9188 KB Output is correct
34 Correct 601 ms 9656 KB Output is correct
35 Partially correct 1082 ms 20108 KB Output is partially correct
36 Partially correct 1092 ms 19948 KB Output is partially correct
37 Correct 909 ms 14788 KB Output is correct
38 Correct 889 ms 14820 KB Output is correct
39 Correct 985 ms 18140 KB Output is correct
40 Correct 961 ms 18816 KB Output is correct
41 Partially correct 1133 ms 20896 KB Output is partially correct
42 Partially correct 1099 ms 20936 KB Output is partially correct
43 Correct 24 ms 1532 KB Output is correct
44 Correct 229 ms 3536 KB Output is correct
45 Correct 1049 ms 19380 KB Output is correct
46 Correct 306 ms 7012 KB Output is correct
47 Correct 562 ms 11376 KB Output is correct
48 Correct 430 ms 9124 KB Output is correct