Submission #978592

# Submission time Handle Problem Language Result Execution time Memory
978592 2024-05-09T11:12:43 Z Temmie Rarest Insects (IOI22_insects) C++17
99.84 / 100
1039 ms 16792 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();
	// return 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;
	srand(time(0));
	for (int l = 2, r = n / uniq; l <= r; ) {
		int mid = (1 + l + r) >> 1;
		in.clear();
		std::vector <int> new_pool;
		std::random_shuffle(pool.begin(), pool.end());
		std::random_shuffle(pool.begin(), pool.end());
		for (int i : pool) {
			inside(i);
			in.push_back(i);
			if ((int) IN.size() == uniq * mid + 1 || 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 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 4 ms 960 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 7 ms 1120 KB Output is correct
14 Correct 6 ms 1112 KB Output is correct
15 Correct 7 ms 1112 KB Output is correct
16 Correct 7 ms 960 KB Output is correct
17 Correct 7 ms 1208 KB Output is correct
18 Correct 7 ms 700 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 344 KB Output is correct
22 Correct 4 ms 772 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 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 4 ms 960 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 7 ms 1120 KB Output is correct
14 Correct 6 ms 1112 KB Output is correct
15 Correct 7 ms 1112 KB Output is correct
16 Correct 7 ms 960 KB Output is correct
17 Correct 7 ms 1208 KB Output is correct
18 Correct 7 ms 700 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 344 KB Output is correct
22 Correct 4 ms 772 KB Output is correct
23 Correct 119 ms 2828 KB Output is correct
24 Correct 94 ms 2752 KB Output is correct
25 Correct 200 ms 3924 KB Output is correct
26 Correct 249 ms 4512 KB Output is correct
27 Correct 93 ms 2176 KB Output is correct
28 Correct 69 ms 2004 KB Output is correct
29 Correct 129 ms 2744 KB Output is correct
30 Correct 155 ms 3472 KB Output is correct
31 Correct 158 ms 3452 KB Output is correct
32 Correct 179 ms 3928 KB Output is correct
33 Correct 209 ms 4288 KB Output is correct
34 Correct 193 ms 4076 KB Output is correct
35 Correct 191 ms 4284 KB Output is correct
36 Correct 217 ms 4188 KB Output is correct
37 Correct 245 ms 4796 KB Output is correct
38 Correct 183 ms 3916 KB Output is correct
39 Correct 214 ms 4188 KB Output is correct
40 Correct 147 ms 3104 KB Output is correct
41 Correct 89 ms 1848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 500 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 508 ms 8904 KB Output is correct
8 Correct 421 ms 8844 KB Output is correct
9 Correct 798 ms 13088 KB Output is correct
10 Correct 778 ms 10400 KB Output is correct
11 Correct 422 ms 5164 KB Output is correct
12 Correct 568 ms 9108 KB Output is correct
13 Correct 596 ms 7980 KB Output is correct
14 Correct 761 ms 9864 KB Output is correct
15 Correct 657 ms 11480 KB Output is correct
16 Correct 683 ms 12316 KB Output is correct
17 Correct 744 ms 12640 KB Output is correct
18 Correct 777 ms 12972 KB Output is correct
19 Correct 763 ms 12548 KB Output is correct
20 Correct 829 ms 13756 KB Output is correct
21 Correct 998 ms 16284 KB Output is correct
22 Correct 824 ms 11736 KB Output is correct
23 Correct 857 ms 12860 KB Output is correct
24 Correct 813 ms 12728 KB Output is correct
25 Correct 629 ms 11176 KB Output is correct
26 Correct 368 ms 6672 KB Output is correct
27 Correct 779 ms 14224 KB Output is correct
28 Correct 764 ms 13056 KB Output is correct
29 Correct 728 ms 12928 KB Output is correct
30 Correct 711 ms 12116 KB Output is correct
31 Correct 796 ms 11440 KB Output is correct
32 Correct 797 ms 11380 KB Output is correct
33 Partially correct 842 ms 12176 KB Output is partially correct
34 Partially correct 847 ms 12300 KB Output is partially correct
35 Correct 801 ms 14728 KB Output is correct
36 Correct 809 ms 13884 KB Output is correct
37 Correct 990 ms 16460 KB Output is correct
38 Correct 1039 ms 16792 KB Output is correct
39 Correct 914 ms 14876 KB Output is correct
40 Correct 908 ms 14736 KB Output is correct
41 Correct 800 ms 13048 KB Output is correct
42 Correct 792 ms 12680 KB Output is correct
43 Correct 28 ms 1808 KB Output is correct
44 Correct 284 ms 3616 KB Output is correct
45 Correct 543 ms 9288 KB Output is correct
46 Correct 330 ms 6700 KB Output is correct
47 Correct 579 ms 10604 KB Output is correct
48 Correct 430 ms 8928 KB Output is correct