Submission #1063149

# Submission time Handle Problem Language Result Execution time Memory
1063149 2024-08-17T14:41:14 Z Arapak Rarest Insects (IOI22_insects) C++17
99.77 / 100
46 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) {
		for(auto x : vals)
			removed[x] = true;
		t = v;
	}
	else {
		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(3)) return 4;
		if(solve(2)) return 3;
		if(solve(1)) return 2;
		return 1;
	}

	dbg(ind);
	int t = 0;
	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;
	}
	return b + 1;
}

Compilation message

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