Submission #1063155

# Submission time Handle Problem Language Result Execution time Memory
1063155 2024-08-17T14:42:53 Z Arapak Rarest Insects (IOI22_insects) C++17
98.2 / 100
54 ms 852 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(4)) return 5;
		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:121:6: warning: unused variable 't' [-Wunused-variable]
  121 |  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 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 4 ms 404 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 2 ms 436 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 4 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 5 ms 432 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 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 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 4 ms 404 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 2 ms 436 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 4 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 5 ms 432 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 17 ms 444 KB Output is correct
24 Correct 5 ms 340 KB Output is correct
25 Correct 8 ms 432 KB Output is correct
26 Correct 14 ms 424 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 12 ms 600 KB Output is correct
29 Correct 13 ms 344 KB Output is correct
30 Correct 13 ms 440 KB Output is correct
31 Correct 21 ms 344 KB Output is correct
32 Correct 10 ms 344 KB Output is correct
33 Correct 9 ms 344 KB Output is correct
34 Correct 11 ms 600 KB Output is correct
35 Correct 16 ms 440 KB Output is correct
36 Correct 13 ms 600 KB Output is correct
37 Correct 16 ms 436 KB Output is correct
38 Correct 12 ms 344 KB Output is correct
39 Correct 9 ms 344 KB Output is correct
40 Correct 19 ms 344 KB Output is correct
41 Correct 11 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 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Partially correct 0 ms 344 KB Output is partially correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 34 ms 456 KB Output is correct
8 Correct 9 ms 344 KB Output is correct
9 Correct 23 ms 680 KB Output is correct
10 Correct 36 ms 596 KB Output is correct
11 Correct 36 ms 424 KB Output is correct
12 Correct 18 ms 460 KB Output is correct
13 Correct 19 ms 344 KB Output is correct
14 Correct 28 ms 344 KB Output is correct
15 Correct 31 ms 696 KB Output is correct
16 Correct 31 ms 424 KB Output is correct
17 Correct 36 ms 424 KB Output is correct
18 Correct 31 ms 444 KB Output is correct
19 Correct 26 ms 344 KB Output is correct
20 Correct 43 ms 344 KB Output is correct
21 Correct 28 ms 428 KB Output is correct
22 Correct 29 ms 428 KB Output is correct
23 Correct 26 ms 344 KB Output is correct
24 Partially correct 33 ms 592 KB Output is partially correct
25 Partially correct 24 ms 444 KB Output is partially correct
26 Correct 34 ms 448 KB Output is correct
27 Correct 32 ms 344 KB Output is correct
28 Correct 28 ms 592 KB Output is correct
29 Correct 51 ms 592 KB Output is correct
30 Correct 26 ms 344 KB Output is correct
31 Partially correct 25 ms 592 KB Output is partially correct
32 Partially correct 27 ms 428 KB Output is partially correct
33 Correct 22 ms 344 KB Output is correct
34 Correct 34 ms 436 KB Output is correct
35 Correct 31 ms 344 KB Output is correct
36 Correct 35 ms 344 KB Output is correct
37 Correct 38 ms 424 KB Output is correct
38 Correct 32 ms 432 KB Output is correct
39 Correct 41 ms 344 KB Output is correct
40 Correct 39 ms 428 KB Output is correct
41 Correct 28 ms 448 KB Output is correct
42 Correct 29 ms 592 KB Output is correct
43 Correct 8 ms 600 KB Output is correct
44 Correct 20 ms 424 KB Output is correct
45 Correct 54 ms 592 KB Output is correct
46 Correct 9 ms 452 KB Output is correct
47 Correct 9 ms 344 KB Output is correct
48 Correct 19 ms 852 KB Output is correct