Submission #1078784

#TimeUsernameProblemLanguageResultExecution timeMemory
1078784Gromp15Rarest Insects (IOI22_insects)C++17
58.53 / 100
104 ms928 KiB
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#include "insects.h"
using namespace std;
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

int min_cardinality(int N) {
	vector<int> groups{0};
	move_inside(0);
	for (int i = 1; i < N; i++) {
		move_inside(i);
		if (press_button() > 1) move_outside(i);
		else groups.push_back(i);
	}
	for (int x : groups) move_outside(x);
	if (sz(groups) >= 230) {
		vector<int> rest(N);
		iota(all(rest), 0);
		for (int x : groups) rest.erase(find(all(rest), x));
		int ans = 1;
		while (rest.size()) {
			vector<int> groups2{rest[0]};
			move_inside(rest[0]);
			for (int i = 1; i < sz(rest); i++) {
				move_inside(rest[i]);
				if (press_button() > 1) move_outside(rest[i]);
				else groups2.push_back(rest[i]);
			}
			if (sz(groups2) < sz(groups)) break;
			ans++;
			for (int x : groups2) rest.erase(find(all(rest), x));
		}
		return ans;
	}
	int ans = 1e9;
	auto solve = [&](auto&& s, vector<int> v, vector<int> pot) -> void {
		if (sz(v) == 1) {
			ckmin(ans, sz(pot)); return;
		}
		vector<int> hf(v.begin(), v.begin() + sz(v) / 2), other(v.begin() + sz(v) / 2, v.end());
		for (int x : hf) move_inside(x);
		vector<int> A, B;
		for (int x : pot) {
			if (find(all(hf), x) != hf.end()) A.emplace_back(x);
			else {
				move_inside(x);
				if (press_button() > 1) {
					A.emplace_back(x);
				}
				else {
					B.emplace_back(x);
				}
				move_outside(x);
			}
		}
		for (int x : hf) move_outside(x);
		s(s, hf, A);
		s(s, other, B);
	};
	vector<int> tot(N);
	iota(all(tot), 0);
	solve(solve, groups, tot);
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...