답안 #1063123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063123 2024-08-17T14:26:33 Z Arapak 드문 곤충 (IOI22_insects) C++17
99.77 / 100
42 ms 696 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 + 1;
	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;
}
# 결과 실행 시간 메모리 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 2 ms 344 KB Output is correct
8 Correct 2 ms 432 KB Output is correct
9 Correct 3 ms 440 KB Output is correct
10 Correct 3 ms 432 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 3 ms 344 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 344 KB Output is correct
17 Correct 3 ms 344 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 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 344 KB Output is correct
8 Correct 2 ms 432 KB Output is correct
9 Correct 3 ms 440 KB Output is correct
10 Correct 3 ms 432 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 3 ms 344 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 344 KB Output is correct
17 Correct 3 ms 344 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 1 ms 344 KB Output is correct
23 Correct 16 ms 440 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 14 ms 452 KB Output is correct
26 Correct 15 ms 344 KB Output is correct
27 Correct 12 ms 344 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 16 ms 436 KB Output is correct
30 Correct 15 ms 592 KB Output is correct
31 Correct 23 ms 344 KB Output is correct
32 Correct 12 ms 344 KB Output is correct
33 Correct 12 ms 344 KB Output is correct
34 Correct 21 ms 344 KB Output is correct
35 Correct 13 ms 344 KB Output is correct
36 Correct 13 ms 344 KB Output is correct
37 Correct 13 ms 344 KB Output is correct
38 Correct 10 ms 444 KB Output is correct
39 Correct 16 ms 440 KB Output is correct
40 Correct 8 ms 444 KB Output is correct
41 Correct 6 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 31 ms 428 KB Output is correct
8 Correct 10 ms 344 KB Output is correct
9 Correct 26 ms 432 KB Output is correct
10 Correct 39 ms 344 KB Output is correct
11 Correct 21 ms 428 KB Output is correct
12 Correct 11 ms 344 KB Output is correct
13 Correct 37 ms 428 KB Output is correct
14 Correct 27 ms 344 KB Output is correct
15 Correct 32 ms 344 KB Output is correct
16 Correct 34 ms 592 KB Output is correct
17 Correct 29 ms 448 KB Output is correct
18 Correct 32 ms 344 KB Output is correct
19 Correct 39 ms 440 KB Output is correct
20 Correct 25 ms 428 KB Output is correct
21 Correct 28 ms 428 KB Output is correct
22 Partially correct 24 ms 600 KB Output is partially correct
23 Correct 31 ms 428 KB Output is correct
24 Correct 35 ms 600 KB Output is correct
25 Correct 20 ms 448 KB Output is correct
26 Correct 9 ms 600 KB Output is correct
27 Correct 25 ms 424 KB Output is correct
28 Correct 33 ms 440 KB Output is correct
29 Correct 35 ms 428 KB Output is correct
30 Correct 34 ms 424 KB Output is correct
31 Partially correct 42 ms 592 KB Output is partially correct
32 Partially correct 31 ms 428 KB Output is partially correct
33 Correct 35 ms 424 KB Output is correct
34 Correct 30 ms 436 KB Output is correct
35 Correct 19 ms 428 KB Output is correct
36 Correct 30 ms 440 KB Output is correct
37 Correct 24 ms 444 KB Output is correct
38 Correct 26 ms 428 KB Output is correct
39 Correct 25 ms 696 KB Output is correct
40 Correct 28 ms 344 KB Output is correct
41 Correct 18 ms 592 KB Output is correct
42 Correct 24 ms 592 KB Output is correct
43 Correct 4 ms 344 KB Output is correct
44 Correct 18 ms 344 KB Output is correct
45 Correct 30 ms 344 KB Output is correct
46 Correct 18 ms 600 KB Output is correct
47 Correct 19 ms 600 KB Output is correct
48 Correct 12 ms 456 KB Output is correct