Submission #631123

# Submission time Handle Problem Language Result Execution time Memory
631123 2022-08-17T17:34:08 Z kingmoshe Rarest Insects (IOI22_insects) C++17
99.95 / 100
65 ms 420 KB
#include "insects.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <random>


/*std::vector<int> types(0);
std::vector<int> inside(0);
int maximal_type = 0;

void move_inside(int i) {
	inside.push_back(i);
}
void move_outside(int i) {
	for (int j = 0; j < inside.size(); j++) {
		if (inside[j] == i) {
			inside.erase(inside.begin() + j);
			break;
		}
	}
}
int real_result() {
	std::vector<int> values(maximal_type + 1);
	for (int i = 0; i < types.size(); i++) {
		values[types[i]] += 1;
	}
	int result = 100000;
	for (int i = 0; i < values.size(); i++) {
		if (values[i] != 0 && values[i] < result) {
			result = values[i];
		}
	}
	return result;
}
int press_button() {
	std::vector<int> values(maximal_type + 1);
	int max_res = 0;
	for (int i = 0; i < inside.size(); i++) {
		values[types[inside[i]]] += 1;
		if (values[types[inside[i]]] > max_res) {
			max_res = values[types[inside[i]]];
		}
	}
	return max_res;
}//*/
std::vector<int> shuffle(0);
void move_inside2(int i) {
	move_inside(shuffle[i]);
}
void move_outside2(int i) {
	move_outside(shuffle[i]);
}
std::vector<bool> visited(0);
void init(int N) {
	visited.resize(N, false);
	shuffle.resize(N);
	for (int i = 0; i < N; i++) {
		shuffle[i] = i;
	}
	std::random_shuffle(shuffle.begin(), shuffle.end());
}
int get_number_of_types(int N) {
	move_inside(0);
	int counter = 1;
	visited[0] = true;
	for (int i = 1; i < N; i++) {
		move_inside(i);
		int value = press_button();
		if (value == 1) {
			visited[i] = true;
			counter += 1;
		}
		else {
			move_outside(i);
		}
	}
	return counter;
}
void remove_all_indexes(std::vector<int> indexes) {
	for (int i = 0; i < int(indexes.size()); i++) {
		move_outside(indexes[i]);
	}
}
int first_solution(int N) {
	int number_of_types = get_number_of_types(N);
	int current_result = 1;
	std::vector<int> inside_indexes(0);
	bool any_change = true;
	while (any_change) {
		any_change = false;
		for (int i = 0; i < N; i++) {
			if (visited[i]) {
				continue;
			}
			move_inside(i);
			int value = press_button();
			if (value > current_result + 1) {
				move_outside(i);
			}
			else {
				visited[i] = true;
				inside_indexes.push_back(i);
			}
			if (int(inside_indexes.size()) == number_of_types) {
				current_result += 1;
				any_change = true;
				inside_indexes.resize(0);
			}
		}
		for (int i = 0; i < int(inside_indexes.size()); i++) {
			visited[inside_indexes[i]] = false;
		}
		remove_all_indexes(inside_indexes);
		inside_indexes.resize(0);
	}
	return current_result;
}
int get_best_t(int size, int k) {
	int t = size / (k + k);
	t += 5;
	while (t * k * 2 > size) {
		t -= 1;
	}
	return t;
}
int second_solution(int N) {
	int k = get_number_of_types(N);
	int amount_left = N - k;
	int found_so_far = 1;
	while (true) {
		int t = get_best_t(amount_left, k);
		std::vector<int> inside_indexes(0);
		inside_indexes.resize(0);
		if (k > amount_left) {
			return found_so_far;
		}
		if (k + k > amount_left) {
			t = 1;
		}
		for (int i = 0; i < N; i++) {
			if (visited[i]) {
				continue;
			}
			move_inside(i);
			int value = press_button();
			if (value > t + found_so_far) {
				move_outside(i);
			}
			else {
				inside_indexes.push_back(i);
				visited[i] = true;
			}
			if (int(inside_indexes.size()) == k * t) {
				break;
			}
		}
		if (int(inside_indexes.size()) == k * t) {
			found_so_far += t;
			amount_left -= k * t;
		}
		else if (t == 1) {
			break;
		}
		else {
			for (int i = 0; i < N; i++) {
				visited[i] = true;
			}
			amount_left = 0;
			for (int i = 0; i<int(inside_indexes.size()); i++) {
				visited[inside_indexes[i]] = false;
				move_outside(inside_indexes[i]);
				amount_left += 1;
			}
		}
	}
	return found_so_far;
}
int min_cardinality(int N) {
	init(N);
	return second_solution(N);
}
/*int main() {
	// 5, 8, 9,5 ,9 ,9
	maximal_type = 20;
	int n = 100;
	for (int i = 0; i < n; i++) {
		types.push_back(rand() % maximal_type);
	}
	//types = { 5 ,8 ,9 ,5 , 9,9, 8 };
	std::cout << min_cardinality(n) << std::endl;
	std::cout << real_result();
}//*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 4 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 2 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 4 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 2 ms 208 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 21 ms 328 KB Output is correct
24 Correct 5 ms 208 KB Output is correct
25 Correct 23 ms 208 KB Output is correct
26 Correct 24 ms 208 KB Output is correct
27 Correct 25 ms 208 KB Output is correct
28 Correct 11 ms 208 KB Output is correct
29 Correct 25 ms 300 KB Output is correct
30 Correct 27 ms 208 KB Output is correct
31 Correct 24 ms 288 KB Output is correct
32 Correct 12 ms 304 KB Output is correct
33 Correct 19 ms 284 KB Output is correct
34 Correct 24 ms 208 KB Output is correct
35 Correct 15 ms 208 KB Output is correct
36 Correct 28 ms 208 KB Output is correct
37 Correct 19 ms 208 KB Output is correct
38 Correct 19 ms 208 KB Output is correct
39 Correct 17 ms 208 KB Output is correct
40 Correct 15 ms 208 KB Output is correct
41 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 19 ms 300 KB Output is correct
8 Correct 19 ms 208 KB Output is correct
9 Correct 42 ms 288 KB Output is correct
10 Correct 65 ms 208 KB Output is correct
11 Correct 30 ms 292 KB Output is correct
12 Correct 30 ms 208 KB Output is correct
13 Correct 52 ms 208 KB Output is correct
14 Correct 64 ms 292 KB Output is correct
15 Correct 43 ms 292 KB Output is correct
16 Correct 40 ms 284 KB Output is correct
17 Correct 36 ms 296 KB Output is correct
18 Correct 65 ms 284 KB Output is correct
19 Correct 46 ms 208 KB Output is correct
20 Correct 50 ms 208 KB Output is correct
21 Correct 53 ms 284 KB Output is correct
22 Correct 36 ms 420 KB Output is correct
23 Correct 31 ms 208 KB Output is correct
24 Correct 29 ms 288 KB Output is correct
25 Correct 33 ms 296 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 42 ms 328 KB Output is correct
28 Correct 31 ms 288 KB Output is correct
29 Correct 41 ms 208 KB Output is correct
30 Correct 48 ms 292 KB Output is correct
31 Correct 46 ms 292 KB Output is correct
32 Correct 27 ms 328 KB Output is correct
33 Correct 54 ms 208 KB Output is correct
34 Correct 47 ms 288 KB Output is correct
35 Partially correct 41 ms 208 KB Output is partially correct
36 Correct 38 ms 288 KB Output is correct
37 Correct 43 ms 288 KB Output is correct
38 Correct 41 ms 296 KB Output is correct
39 Correct 22 ms 312 KB Output is correct
40 Correct 28 ms 284 KB Output is correct
41 Correct 56 ms 288 KB Output is correct
42 Partially correct 62 ms 208 KB Output is partially correct
43 Correct 10 ms 208 KB Output is correct
44 Correct 49 ms 208 KB Output is correct
45 Correct 44 ms 208 KB Output is correct
46 Correct 35 ms 208 KB Output is correct
47 Correct 28 ms 208 KB Output is correct
48 Correct 44 ms 208 KB Output is correct