Submission #1063184

# Submission time Handle Problem Language Result Execution time Memory
1063184 2024-08-17T14:56:11 Z Arapak Rarest Insects (IOI22_insects) C++17
99.77 / 100
40 ms 600 KB
#include "insects.h"
#include "bits/stdc++.h"

using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#ifdef DEBUG
auto& operator<<(auto& os, pair<auto, auto> &p) {
	return os<<"("<<p.first<<", "<<p.second<<")";
}
auto& operator<<(auto& os, const auto &v) {
	os<<"{";
	for(auto it=begin(v);it!=end(v);++it) {
		if(it != begin(v)) os<<", ";
		os<<(*it);
	}
	return os<<"}";
}

void dbg_out(auto... x) {
	((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x);
#else
#define dbg(...)
#endif

int n;
vi perm;
vi added;

void in(int i) {
	if(added[i]) return;
	added[i] = true;
	move_inside(perm[i]);
}
void out(int i) {
	if(!added[i]) return;
	added[i] = false;
	move_outside(perm[i]);
}

int button() {
	int res = press_button();
	dbg(added, res);
	return res;
}

vi get_k() {
	vi res;
	rep(i,0,n) {
		in(i);
		if(button() > 1)
			out(i);
		else res.push_back(i);
	}
	rep(i,0,n) out(i);
	return res;
}

int k;
vector<bool> removed;

pair<bool, vi> check(int x) {
	rep(i,0,n) {
		if(removed[i]) continue;
		in(i);
		if(button() > x) out(i);
	}
	vi vals;
	rep(i,0,n)
		if(added[i]) vals.push_back(i);
	rep(i,0,n) out(i);
	return {sz(vals) == k*x, vals};
}

int t = 0;

bool solve(int v) {
	auto [poss, vals] = check(v - t);
	if(poss) {
		dbg("DELETED", sz(vals));
		for(auto x : vals)
			removed[x] = true;
		t = v;
	}
	else {
		int num = accumulate(all(removed), 0);
		dbg("DELETED", n - num - sz(vals));

		fill(all(removed), true);
		for(auto x : vals)
			removed[x] = false;
	}
	return poss;
}

int min_cardinality(int N) {
	n = N;
	perm.resize(n);
	iota(all(perm), 0);
	random_shuffle(all(perm));
	added.assign(n, 0);
	vi ind = get_k();
	k = sz(ind);
	removed.assign(n, 0);
	for(auto i : ind)
		removed[i] = true;

	if(k*5 >= n) {
		if(!solve(1)) return 1;
		if(!solve(2)) return 2;
		if(!solve(3)) return 3;
		if(!solve(4)) return 4;
		return 5;
	}

	dbg(ind);
	int b = 0, e = (n - 1) / k;
	while(b < e) {
		int mid = (b + e + 1) / 2;
		if(solve(mid)) b = mid;
		else e = mid - 1;

		int left = n - accumulate(all(removed), 0);
		if(left < k) {
			break;
		}
	}
	return b + 1;
}

Compilation message

insects.cpp: In function 'bool solve(int)':
insects.cpp:94:7: warning: unused variable 'num' [-Wunused-variable]
   94 |   int num = accumulate(all(removed), 0);
      |       ^~~
# 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 4 ms 432 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 4 ms 436 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 3 ms 436 KB Output is correct
17 Correct 3 ms 436 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 436 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 344 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 4 ms 432 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 4 ms 436 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 3 ms 436 KB Output is correct
17 Correct 3 ms 436 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 436 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 12 ms 444 KB Output is correct
24 Correct 4 ms 444 KB Output is correct
25 Correct 15 ms 436 KB Output is correct
26 Correct 12 ms 444 KB Output is correct
27 Correct 16 ms 420 KB Output is correct
28 Correct 7 ms 444 KB Output is correct
29 Correct 14 ms 416 KB Output is correct
30 Correct 16 ms 424 KB Output is correct
31 Correct 17 ms 344 KB Output is correct
32 Correct 15 ms 416 KB Output is correct
33 Correct 18 ms 428 KB Output is correct
34 Correct 15 ms 344 KB Output is correct
35 Correct 14 ms 444 KB Output is correct
36 Correct 18 ms 432 KB Output is correct
37 Correct 13 ms 344 KB Output is correct
38 Correct 12 ms 444 KB Output is correct
39 Correct 11 ms 600 KB Output is correct
40 Correct 9 ms 440 KB Output is correct
41 Correct 6 ms 344 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 0 ms 344 KB Output is correct
7 Correct 39 ms 432 KB Output is correct
8 Correct 10 ms 344 KB Output is correct
9 Correct 28 ms 440 KB Output is correct
10 Correct 39 ms 428 KB Output is correct
11 Correct 25 ms 428 KB Output is correct
12 Correct 20 ms 448 KB Output is correct
13 Correct 31 ms 428 KB Output is correct
14 Correct 28 ms 428 KB Output is correct
15 Correct 28 ms 428 KB Output is correct
16 Correct 40 ms 424 KB Output is correct
17 Correct 30 ms 592 KB Output is correct
18 Correct 23 ms 432 KB Output is correct
19 Correct 28 ms 428 KB Output is correct
20 Correct 32 ms 344 KB Output is correct
21 Correct 22 ms 428 KB Output is correct
22 Correct 24 ms 344 KB Output is correct
23 Correct 19 ms 428 KB Output is correct
24 Correct 19 ms 436 KB Output is correct
25 Correct 22 ms 456 KB Output is correct
26 Correct 15 ms 448 KB Output is correct
27 Correct 23 ms 428 KB Output is correct
28 Correct 25 ms 432 KB Output is correct
29 Correct 28 ms 448 KB Output is correct
30 Correct 31 ms 424 KB Output is correct
31 Partially correct 26 ms 428 KB Output is partially correct
32 Partially correct 34 ms 428 KB Output is partially correct
33 Correct 23 ms 424 KB Output is correct
34 Correct 34 ms 596 KB Output is correct
35 Correct 30 ms 428 KB Output is correct
36 Correct 34 ms 424 KB Output is correct
37 Correct 32 ms 424 KB Output is correct
38 Correct 38 ms 428 KB Output is correct
39 Correct 30 ms 448 KB Output is correct
40 Correct 31 ms 504 KB Output is correct
41 Correct 21 ms 344 KB Output is correct
42 Correct 40 ms 424 KB Output is correct
43 Correct 5 ms 344 KB Output is correct
44 Correct 16 ms 424 KB Output is correct
45 Correct 28 ms 432 KB Output is correct
46 Correct 15 ms 344 KB Output is correct
47 Correct 17 ms 344 KB Output is correct
48 Correct 11 ms 600 KB Output is correct