Submission #978601

# Submission time Handle Problem Language Result Execution time Memory
978601 2024-05-09T11:15:47 Z Temmie Rarest Insects (IOI22_insects) C++17
99.95 / 100
1148 ms 20412 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 1 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 4 ms 700 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 6 ms 1368 KB Output is correct
10 Correct 4 ms 704 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 6 ms 596 KB Output is correct
14 Correct 6 ms 508 KB Output is correct
15 Correct 6 ms 856 KB Output is correct
16 Correct 6 ms 1368 KB Output is correct
17 Correct 6 ms 856 KB Output is correct
18 Correct 6 ms 696 KB Output is correct
19 Correct 6 ms 1112 KB Output is correct
20 Correct 6 ms 856 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 3 ms 856 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 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 4 ms 700 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 6 ms 1368 KB Output is correct
10 Correct 4 ms 704 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 6 ms 596 KB Output is correct
14 Correct 6 ms 508 KB Output is correct
15 Correct 6 ms 856 KB Output is correct
16 Correct 6 ms 1368 KB Output is correct
17 Correct 6 ms 856 KB Output is correct
18 Correct 6 ms 696 KB Output is correct
19 Correct 6 ms 1112 KB Output is correct
20 Correct 6 ms 856 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 3 ms 856 KB Output is correct
23 Correct 101 ms 3108 KB Output is correct
24 Correct 93 ms 2788 KB Output is correct
25 Correct 159 ms 4164 KB Output is correct
26 Correct 191 ms 5012 KB Output is correct
27 Correct 70 ms 2268 KB Output is correct
28 Correct 59 ms 1820 KB Output is correct
29 Correct 91 ms 2608 KB Output is correct
30 Correct 122 ms 3980 KB Output is correct
31 Correct 148 ms 4068 KB Output is correct
32 Correct 161 ms 4128 KB Output is correct
33 Correct 186 ms 4408 KB Output is correct
34 Correct 174 ms 4400 KB Output is correct
35 Correct 158 ms 4320 KB Output is correct
36 Correct 168 ms 3956 KB Output is correct
37 Correct 182 ms 4964 KB Output is correct
38 Correct 128 ms 3120 KB Output is correct
39 Correct 127 ms 3656 KB Output is correct
40 Correct 126 ms 3760 KB Output is correct
41 Correct 71 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 451 ms 9568 KB Output is correct
8 Correct 405 ms 8668 KB Output is correct
9 Correct 755 ms 13928 KB Output is correct
10 Correct 875 ms 15412 KB Output is correct
11 Correct 303 ms 5416 KB Output is correct
12 Correct 565 ms 8796 KB Output is correct
13 Correct 540 ms 7796 KB Output is correct
14 Correct 583 ms 9352 KB Output is correct
15 Correct 621 ms 12196 KB Output is correct
16 Correct 650 ms 12628 KB Output is correct
17 Correct 699 ms 12652 KB Output is correct
18 Correct 792 ms 14572 KB Output is correct
19 Correct 788 ms 14212 KB Output is correct
20 Correct 791 ms 15064 KB Output is correct
21 Correct 865 ms 15208 KB Output is correct
22 Correct 796 ms 12812 KB Output is correct
23 Correct 601 ms 10384 KB Output is correct
24 Correct 746 ms 12924 KB Output is correct
25 Correct 624 ms 11436 KB Output is correct
26 Correct 365 ms 7000 KB Output is correct
27 Correct 987 ms 18444 KB Output is correct
28 Correct 484 ms 8992 KB Output is correct
29 Correct 1028 ms 20412 KB Output is correct
30 Correct 1044 ms 19708 KB Output is correct
31 Correct 896 ms 14980 KB Output is correct
32 Correct 891 ms 16192 KB Output is correct
33 Correct 616 ms 9536 KB Output is correct
34 Correct 600 ms 9120 KB Output is correct
35 Partially correct 1067 ms 19752 KB Output is partially correct
36 Correct 873 ms 15660 KB Output is correct
37 Correct 921 ms 14444 KB Output is correct
38 Correct 925 ms 14548 KB Output is correct
39 Correct 1000 ms 18236 KB Output is correct
40 Correct 497 ms 8976 KB Output is correct
41 Correct 871 ms 15404 KB Output is correct
42 Partially correct 1148 ms 20168 KB Output is partially correct
43 Correct 30 ms 1636 KB Output is correct
44 Correct 247 ms 3600 KB Output is correct
45 Correct 512 ms 9200 KB Output is correct
46 Correct 344 ms 6704 KB Output is correct
47 Correct 628 ms 10596 KB Output is correct
48 Correct 453 ms 8764 KB Output is correct