Submission #1063131

# Submission time Handle Problem Language Result Execution time Memory
1063131 2024-08-17T14:32:51 Z Arapak Rarest Insects (IOI22_insects) C++17
99.77 / 100
46 ms 844 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 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;
	dbg(ind);
	int t = 0;
	int b = 0, e = n / k;
	while(b < e) {
		int mid = (b + e + 1) / 2;
		auto [poss, vals] = check(mid - t);
		if(poss) {
			b = mid;
			for(auto x : vals)
				removed[x] = true;
			t = mid;
		}
		else {
			e = mid - 1;
			fill(all(removed), true);
			for(auto x : vals)
				removed[x] = false;
		}
	}
	return b + 1;
}
# 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 3 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 436 KB Output is correct
16 Correct 3 ms 432 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 344 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 0 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 436 KB Output is correct
16 Correct 3 ms 432 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 4 ms 344 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 14 ms 444 KB Output is correct
24 Correct 5 ms 600 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 13 ms 600 KB Output is correct
27 Correct 11 ms 600 KB Output is correct
28 Correct 7 ms 340 KB Output is correct
29 Correct 11 ms 344 KB Output is correct
30 Correct 8 ms 344 KB Output is correct
31 Correct 10 ms 344 KB Output is correct
32 Correct 12 ms 344 KB Output is correct
33 Correct 16 ms 592 KB Output is correct
34 Correct 12 ms 600 KB Output is correct
35 Correct 13 ms 416 KB Output is correct
36 Correct 10 ms 344 KB Output is correct
37 Correct 9 ms 344 KB Output is correct
38 Correct 11 ms 592 KB Output is correct
39 Correct 10 ms 344 KB Output is correct
40 Correct 8 ms 344 KB Output is correct
41 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 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 33 ms 440 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 24 ms 700 KB Output is correct
10 Correct 31 ms 592 KB Output is correct
11 Correct 27 ms 592 KB Output is correct
12 Correct 15 ms 456 KB Output is correct
13 Correct 34 ms 432 KB Output is correct
14 Correct 29 ms 344 KB Output is correct
15 Correct 30 ms 344 KB Output is correct
16 Correct 37 ms 592 KB Output is correct
17 Correct 30 ms 592 KB Output is correct
18 Correct 42 ms 844 KB Output is correct
19 Correct 46 ms 440 KB Output is correct
20 Correct 30 ms 344 KB Output is correct
21 Correct 23 ms 592 KB Output is correct
22 Correct 33 ms 680 KB Output is correct
23 Correct 37 ms 344 KB Output is correct
24 Correct 24 ms 592 KB Output is correct
25 Correct 22 ms 600 KB Output is correct
26 Correct 13 ms 708 KB Output is correct
27 Correct 25 ms 592 KB Output is correct
28 Correct 24 ms 592 KB Output is correct
29 Correct 26 ms 344 KB Output is correct
30 Correct 43 ms 592 KB Output is correct
31 Partially correct 38 ms 592 KB Output is partially correct
32 Partially correct 38 ms 428 KB Output is partially correct
33 Correct 37 ms 428 KB Output is correct
34 Correct 27 ms 428 KB Output is correct
35 Correct 25 ms 344 KB Output is correct
36 Correct 24 ms 344 KB Output is correct
37 Correct 31 ms 344 KB Output is correct
38 Correct 25 ms 344 KB Output is correct
39 Correct 30 ms 344 KB Output is correct
40 Correct 33 ms 592 KB Output is correct
41 Correct 28 ms 596 KB Output is correct
42 Correct 36 ms 440 KB Output is correct
43 Correct 6 ms 436 KB Output is correct
44 Correct 29 ms 420 KB Output is correct
45 Correct 35 ms 444 KB Output is correct
46 Correct 12 ms 456 KB Output is correct
47 Correct 13 ms 600 KB Output is correct
48 Correct 12 ms 344 KB Output is correct