Submission #978586

# Submission time Handle Problem Language Result Execution time Memory
978586 2024-05-09T11:10:58 Z Temmie Rarest Insects (IOI22_insects) C++17
99.84 / 100
1073 ms 16292 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());
		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 5 ms 1112 KB Output is correct
7 Correct 5 ms 860 KB Output is correct
8 Correct 6 ms 856 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 5 ms 876 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 6 ms 712 KB Output is correct
14 Correct 6 ms 780 KB Output is correct
15 Correct 6 ms 868 KB Output is correct
16 Correct 6 ms 856 KB Output is correct
17 Correct 6 ms 856 KB Output is correct
18 Correct 7 ms 888 KB Output is correct
19 Correct 6 ms 712 KB Output is correct
20 Correct 7 ms 1408 KB Output is correct
21 Correct 5 ms 856 KB Output is correct
22 Correct 3 ms 856 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 5 ms 1112 KB Output is correct
7 Correct 5 ms 860 KB Output is correct
8 Correct 6 ms 856 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 5 ms 876 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 6 ms 712 KB Output is correct
14 Correct 6 ms 780 KB Output is correct
15 Correct 6 ms 868 KB Output is correct
16 Correct 6 ms 856 KB Output is correct
17 Correct 6 ms 856 KB Output is correct
18 Correct 7 ms 888 KB Output is correct
19 Correct 6 ms 712 KB Output is correct
20 Correct 7 ms 1408 KB Output is correct
21 Correct 5 ms 856 KB Output is correct
22 Correct 3 ms 856 KB Output is correct
23 Correct 117 ms 3020 KB Output is correct
24 Correct 89 ms 3012 KB Output is correct
25 Correct 185 ms 4064 KB Output is correct
26 Correct 241 ms 4800 KB Output is correct
27 Correct 76 ms 2004 KB Output is correct
28 Correct 58 ms 1964 KB Output is correct
29 Correct 116 ms 2172 KB Output is correct
30 Correct 155 ms 3536 KB Output is correct
31 Correct 150 ms 3712 KB Output is correct
32 Correct 185 ms 3964 KB Output is correct
33 Correct 190 ms 4080 KB Output is correct
34 Correct 185 ms 4844 KB Output is correct
35 Correct 191 ms 4344 KB Output is correct
36 Correct 211 ms 4488 KB Output is correct
37 Correct 237 ms 5280 KB Output is correct
38 Correct 185 ms 3592 KB Output is correct
39 Correct 209 ms 4792 KB Output is correct
40 Correct 145 ms 3984 KB Output is correct
41 Correct 78 ms 2944 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 1 ms 344 KB Output is correct
7 Correct 499 ms 9336 KB Output is correct
8 Correct 419 ms 8756 KB Output is correct
9 Correct 725 ms 12776 KB Output is correct
10 Correct 770 ms 10920 KB Output is correct
11 Correct 401 ms 5312 KB Output is correct
12 Correct 567 ms 9128 KB Output is correct
13 Correct 582 ms 8000 KB Output is correct
14 Correct 807 ms 10492 KB Output is correct
15 Correct 665 ms 11268 KB Output is correct
16 Correct 672 ms 11700 KB Output is correct
17 Correct 739 ms 12736 KB Output is correct
18 Correct 761 ms 12844 KB Output is correct
19 Correct 807 ms 12780 KB Output is correct
20 Correct 892 ms 14624 KB Output is correct
21 Correct 1073 ms 16292 KB Output is correct
22 Correct 863 ms 11340 KB Output is correct
23 Correct 967 ms 12360 KB Output is correct
24 Correct 897 ms 12860 KB Output is correct
25 Correct 695 ms 10668 KB Output is correct
26 Correct 428 ms 6520 KB Output is correct
27 Correct 862 ms 13352 KB Output is correct
28 Correct 851 ms 13372 KB Output is correct
29 Correct 711 ms 11748 KB Output is correct
30 Correct 740 ms 11528 KB Output is correct
31 Correct 810 ms 11160 KB Output is correct
32 Correct 808 ms 11056 KB Output is correct
33 Partially correct 863 ms 12040 KB Output is partially correct
34 Partially correct 852 ms 12420 KB Output is partially correct
35 Correct 796 ms 13892 KB Output is correct
36 Correct 766 ms 13268 KB Output is correct
37 Correct 977 ms 16100 KB Output is correct
38 Correct 965 ms 16076 KB Output is correct
39 Correct 878 ms 16180 KB Output is correct
40 Correct 892 ms 15516 KB Output is correct
41 Correct 848 ms 13980 KB Output is correct
42 Correct 792 ms 13824 KB Output is correct
43 Correct 24 ms 1624 KB Output is correct
44 Correct 262 ms 3252 KB Output is correct
45 Correct 522 ms 9408 KB Output is correct
46 Correct 305 ms 7264 KB Output is correct
47 Correct 555 ms 10880 KB Output is correct
48 Correct 437 ms 8708 KB Output is correct