Submission #834842

# Submission time Handle Problem Language Result Execution time Memory
834842 2023-08-22T20:58:27 Z esomer Rarest Insects (IOI22_insects) C++17
99.6 / 100
55 ms 316 KB
#include<bits/stdc++.h>
#include "insects.h"

using namespace std;

int groups, lft;
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 * groups);
	bst++;
	int mn2 = min(bst * groups, lft - bst * groups);
	if(mn1 < mn2) bst--;
	return max(lo, min(hi, lo + bst - 1));
}

int min_cardinality(int N) {
	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;
		for(int i = 0; i < N; i++) {
			if(done[i]) { continue; }
			move_inside(i);
			int rep = press_button();
			if(rep > mid) {
				bad.push_back(i);
				move_outside(i);
			} else { good.push_back(i); }
		}
		// cout << "lo " << lo << " hi " << hi << " mid " << mid << " ans " << ans << " groups "<<groups << " lft " << lft << 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;
			lft -= (int)bad.size();
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 5 ms 296 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 300 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 5 ms 300 KB Output is correct
15 Correct 4 ms 300 KB Output is correct
16 Correct 5 ms 296 KB Output is correct
17 Correct 6 ms 300 KB Output is correct
18 Correct 8 ms 300 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 4 ms 296 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 5 ms 296 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 300 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 5 ms 300 KB Output is correct
15 Correct 4 ms 300 KB Output is correct
16 Correct 5 ms 296 KB Output is correct
17 Correct 6 ms 300 KB Output is correct
18 Correct 8 ms 300 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 4 ms 296 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 12 ms 304 KB Output is correct
24 Correct 8 ms 256 KB Output is correct
25 Correct 10 ms 300 KB Output is correct
26 Correct 22 ms 284 KB Output is correct
27 Correct 9 ms 296 KB Output is correct
28 Correct 7 ms 208 KB Output is correct
29 Correct 24 ms 208 KB Output is correct
30 Correct 10 ms 304 KB Output is correct
31 Correct 19 ms 208 KB Output is correct
32 Correct 20 ms 208 KB Output is correct
33 Correct 23 ms 304 KB Output is correct
34 Correct 14 ms 304 KB Output is correct
35 Correct 33 ms 296 KB Output is correct
36 Correct 24 ms 296 KB Output is correct
37 Correct 24 ms 304 KB Output is correct
38 Correct 11 ms 300 KB Output is correct
39 Correct 17 ms 288 KB Output is correct
40 Correct 14 ms 208 KB Output is correct
41 Correct 10 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 23 ms 208 KB Output is correct
8 Correct 9 ms 208 KB Output is correct
9 Correct 41 ms 276 KB Output is correct
10 Correct 45 ms 288 KB Output is correct
11 Correct 20 ms 208 KB Output is correct
12 Correct 27 ms 288 KB Output is correct
13 Correct 40 ms 292 KB Output is correct
14 Correct 25 ms 288 KB Output is correct
15 Correct 21 ms 316 KB Output is correct
16 Correct 38 ms 280 KB Output is correct
17 Correct 40 ms 288 KB Output is correct
18 Partially correct 24 ms 288 KB Output is partially correct
19 Correct 50 ms 292 KB Output is correct
20 Correct 30 ms 284 KB Output is correct
21 Correct 23 ms 288 KB Output is correct
22 Partially correct 48 ms 288 KB Output is partially correct
23 Correct 37 ms 288 KB Output is correct
24 Correct 30 ms 292 KB Output is correct
25 Correct 16 ms 280 KB Output is correct
26 Correct 16 ms 208 KB Output is correct
27 Correct 35 ms 284 KB Output is correct
28 Correct 46 ms 288 KB Output is correct
29 Correct 52 ms 208 KB Output is correct
30 Correct 35 ms 284 KB Output is correct
31 Correct 53 ms 296 KB Output is correct
32 Correct 46 ms 280 KB Output is correct
33 Partially correct 50 ms 284 KB Output is partially correct
34 Partially correct 26 ms 308 KB Output is partially correct
35 Correct 50 ms 284 KB Output is correct
36 Correct 55 ms 296 KB Output is correct
37 Correct 32 ms 284 KB Output is correct
38 Correct 51 ms 284 KB Output is correct
39 Correct 50 ms 288 KB Output is correct
40 Correct 34 ms 288 KB Output is correct
41 Correct 38 ms 288 KB Output is correct
42 Correct 52 ms 284 KB Output is correct
43 Correct 7 ms 208 KB Output is correct
44 Correct 30 ms 284 KB Output is correct
45 Correct 36 ms 208 KB Output is correct
46 Correct 20 ms 280 KB Output is correct
47 Correct 22 ms 276 KB Output is correct
48 Correct 15 ms 208 KB Output is correct