Submission #978596

# Submission time Handle Problem Language Result Execution time Memory
978596 2024-05-09T11:14:07 Z Temmie Rarest Insects (IOI22_insects) C++17
100 / 100
1000 ms 16452 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 = (l + r) >> 1;
		in.clear();
		std::vector <int> new_pool;
		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 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 6 ms 1112 KB Output is correct
7 Correct 4 ms 1156 KB Output is correct
8 Correct 8 ms 804 KB Output is correct
9 Correct 7 ms 1040 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 3 ms 1232 KB Output is correct
12 Correct 6 ms 1216 KB Output is correct
13 Correct 6 ms 856 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 6 ms 1120 KB Output is correct
16 Correct 6 ms 1556 KB Output is correct
17 Correct 7 ms 856 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 8 ms 1372 KB Output is correct
20 Correct 7 ms 984 KB Output is correct
21 Correct 5 ms 856 KB Output is correct
22 Correct 4 ms 1128 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 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 6 ms 1112 KB Output is correct
7 Correct 4 ms 1156 KB Output is correct
8 Correct 8 ms 804 KB Output is correct
9 Correct 7 ms 1040 KB Output is correct
10 Correct 5 ms 1884 KB Output is correct
11 Correct 3 ms 1232 KB Output is correct
12 Correct 6 ms 1216 KB Output is correct
13 Correct 6 ms 856 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 6 ms 1120 KB Output is correct
16 Correct 6 ms 1556 KB Output is correct
17 Correct 7 ms 856 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 8 ms 1372 KB Output is correct
20 Correct 7 ms 984 KB Output is correct
21 Correct 5 ms 856 KB Output is correct
22 Correct 4 ms 1128 KB Output is correct
23 Correct 115 ms 2584 KB Output is correct
24 Correct 92 ms 3212 KB Output is correct
25 Correct 190 ms 3840 KB Output is correct
26 Correct 236 ms 4872 KB Output is correct
27 Correct 78 ms 1528 KB Output is correct
28 Correct 67 ms 2052 KB Output is correct
29 Correct 127 ms 2468 KB Output is correct
30 Correct 167 ms 3240 KB Output is correct
31 Correct 155 ms 3916 KB Output is correct
32 Correct 191 ms 4532 KB Output is correct
33 Correct 219 ms 4352 KB Output is correct
34 Correct 196 ms 3924 KB Output is correct
35 Correct 182 ms 4016 KB Output is correct
36 Correct 214 ms 3976 KB Output is correct
37 Correct 225 ms 4624 KB Output is correct
38 Correct 163 ms 3508 KB Output is correct
39 Correct 163 ms 3348 KB Output is correct
40 Correct 140 ms 3416 KB Output is correct
41 Correct 79 ms 2972 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 0 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 509 ms 9440 KB Output is correct
8 Correct 437 ms 8672 KB Output is correct
9 Correct 829 ms 13972 KB Output is correct
10 Correct 976 ms 15164 KB Output is correct
11 Correct 409 ms 5116 KB Output is correct
12 Correct 571 ms 8652 KB Output is correct
13 Correct 577 ms 7396 KB Output is correct
14 Correct 756 ms 9236 KB Output is correct
15 Correct 678 ms 11436 KB Output is correct
16 Correct 702 ms 11888 KB Output is correct
17 Correct 725 ms 12580 KB Output is correct
18 Correct 767 ms 12956 KB Output is correct
19 Correct 806 ms 13240 KB Output is correct
20 Correct 856 ms 13604 KB Output is correct
21 Correct 999 ms 15196 KB Output is correct
22 Correct 899 ms 11708 KB Output is correct
23 Correct 710 ms 9808 KB Output is correct
24 Correct 924 ms 12960 KB Output is correct
25 Correct 691 ms 11112 KB Output is correct
26 Correct 374 ms 6736 KB Output is correct
27 Correct 781 ms 12996 KB Output is correct
28 Correct 843 ms 14344 KB Output is correct
29 Correct 706 ms 12728 KB Output is correct
30 Correct 698 ms 12604 KB Output is correct
31 Correct 1000 ms 16452 KB Output is correct
32 Correct 909 ms 14932 KB Output is correct
33 Correct 722 ms 11508 KB Output is correct
34 Correct 716 ms 11024 KB Output is correct
35 Correct 848 ms 14488 KB Output is correct
36 Correct 737 ms 12860 KB Output is correct
37 Correct 963 ms 16008 KB Output is correct
38 Correct 984 ms 16332 KB Output is correct
39 Correct 827 ms 14676 KB Output is correct
40 Correct 849 ms 14568 KB Output is correct
41 Correct 863 ms 14852 KB Output is correct
42 Correct 852 ms 14840 KB Output is correct
43 Correct 24 ms 1244 KB Output is correct
44 Correct 243 ms 3616 KB Output is correct
45 Correct 518 ms 9292 KB Output is correct
46 Correct 309 ms 7028 KB Output is correct
47 Correct 547 ms 10664 KB Output is correct
48 Correct 421 ms 9024 KB Output is correct