답안 #857962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857962 2023-10-07T08:09:40 Z vjudge1 드문 곤충 (IOI22_insects) C++17
100 / 100
30 ms 860 KB
#include<bits/stdc++.h>
#include "insects.h"
 
using namespace std;
 
mt19937 gen(time(0));
 
int groups, lft, first;
vector<bool> done;
 
int get_groups(int N){
	int groups = 0;
	for(int i = 0; i < N; i++){
		move_inside(i);
		int rep = press_button();
		if(rep > 1) { move_outside(i); }
		else { groups++; done[i] = 1; }
	}
	return groups;
}
 
int choose_best(int lo, int hi){
	//If I choose mid. Then in the case that all the groups are of size at least mid,
	//I discard (mid - lo + 1) * groups.
	//In the other case, I discard left - chosen (and chosen can be at most (mid - lo + 1) * groups).
	//So I want min((mid - lo + 1) * groups, left - (mid - lo + 1) * groups) to be the maximum.
	int x = lft / 2;
	int bst = x / groups;
	int mn1 = min(bst * groups, lft - (bst - 1) * groups);
	if(first)
	bst++;
	int mn2 = min(bst * groups, lft - (bst - 1) * groups);
	if(mn1 < mn2) bst--;
	return max(lo, min(hi, lo + bst - 1));
}
 
int min_cardinality(int N) {
	first = 1;
	done.assign(N, 0);
	int ans = 1;
	groups = get_groups(N);
	lft = N - groups;
	int cnt = groups;
	int lo = 2;
	int hi = N / groups;
	while(lo <= hi && lft > 0) {
		int mid = choose_best(lo, hi);
		vector<int> good, bad, equal;
		vector<int> possible;
		for(int i = 0; i < N; i++) {
			if(!done[i]) possible.push_back(i);
		}
		while((int)possible.size() > 0){
			if((cnt + (int)good.size()) == mid * groups) {
				bad.push_back(possible.back());
				possible.pop_back();
				continue;
			}
			int ind = gen() % ((int)possible.size());
			int i = possible[ind];
			move_inside(i);
			int rep = press_button();
			if(rep > mid) {
				bad.push_back(i);
				move_outside(i);
			} else { good.push_back(i); }
			// if(rep == mid) equal.push_back(i);
			if(ind != (int)possible.size() - 1) swap(possible[ind], possible[(int)possible.size() - 1]);
			possible.pop_back();
		}
		// cout << "lft "<< lft << " mid " << mid << endl; 
		if((int)good.size() + cnt == mid * groups) {
			ans = mid;
			lo = mid + 1;
			for(int x : good) done[x] = 1;
			cnt += (int)good.size();
			lft -= (int)good.size();
		} else {
			hi = mid - 1;
			for(int x : good) move_outside(x);
			for(int x : bad) done[x] = 1;
			for(int x : equal) done[x] = 1;
			lft -= (int)bad.size() + (int)equal.size();
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 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 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 3 ms 644 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 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 1 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 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 3 ms 644 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 9 ms 600 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 11 ms 856 KB Output is correct
26 Correct 11 ms 684 KB Output is correct
27 Correct 13 ms 448 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 11 ms 856 KB Output is correct
30 Correct 12 ms 688 KB Output is correct
31 Correct 10 ms 596 KB Output is correct
32 Correct 11 ms 436 KB Output is correct
33 Correct 14 ms 696 KB Output is correct
34 Correct 11 ms 848 KB Output is correct
35 Correct 13 ms 600 KB Output is correct
36 Correct 13 ms 600 KB Output is correct
37 Correct 11 ms 856 KB Output is correct
38 Correct 11 ms 600 KB Output is correct
39 Correct 9 ms 448 KB Output is correct
40 Correct 7 ms 696 KB Output is correct
41 Correct 4 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 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 17 ms 596 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 22 ms 692 KB Output is correct
10 Correct 27 ms 452 KB Output is correct
11 Correct 21 ms 600 KB Output is correct
12 Correct 13 ms 600 KB Output is correct
13 Correct 24 ms 440 KB Output is correct
14 Correct 26 ms 436 KB Output is correct
15 Correct 20 ms 592 KB Output is correct
16 Correct 23 ms 860 KB Output is correct
17 Correct 20 ms 668 KB Output is correct
18 Correct 26 ms 428 KB Output is correct
19 Correct 28 ms 600 KB Output is correct
20 Correct 24 ms 676 KB Output is correct
21 Correct 30 ms 612 KB Output is correct
22 Correct 24 ms 688 KB Output is correct
23 Correct 21 ms 672 KB Output is correct
24 Correct 18 ms 608 KB Output is correct
25 Correct 15 ms 676 KB Output is correct
26 Correct 17 ms 344 KB Output is correct
27 Correct 24 ms 436 KB Output is correct
28 Correct 28 ms 592 KB Output is correct
29 Correct 23 ms 684 KB Output is correct
30 Correct 22 ms 600 KB Output is correct
31 Correct 27 ms 600 KB Output is correct
32 Correct 30 ms 668 KB Output is correct
33 Correct 26 ms 848 KB Output is correct
34 Correct 27 ms 600 KB Output is correct
35 Correct 25 ms 448 KB Output is correct
36 Correct 24 ms 600 KB Output is correct
37 Correct 24 ms 852 KB Output is correct
38 Correct 29 ms 448 KB Output is correct
39 Correct 28 ms 600 KB Output is correct
40 Correct 24 ms 436 KB Output is correct
41 Correct 20 ms 428 KB Output is correct
42 Correct 23 ms 432 KB Output is correct
43 Correct 6 ms 452 KB Output is correct
44 Correct 21 ms 436 KB Output is correct
45 Correct 20 ms 432 KB Output is correct
46 Correct 15 ms 440 KB Output is correct
47 Correct 16 ms 416 KB Output is correct
48 Correct 17 ms 672 KB Output is correct