Submission #794437

# Submission time Handle Problem Language Result Execution time Memory
794437 2023-07-26T14:24:14 Z IvanJ Rarest Insects (IOI22_insects) C++17
97.9 / 100
55 ms 448 KB
#include "insects.h"
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

mt19937 rng(1209747089);
const int maxn = 2005;

int n, D, step;
int vis[maxn];
int forb[maxn];
vector<ii> in;
vector<int> p;

int check(int x) {
	int y = -1, lst = 0;
	shuffle(all(p), rng);
	for(int i : p) {
		if(vis[i] || forb[i]) continue;
		move_inside(i);
		int cnt = press_button();
		if(lst < x && cnt == x) y = i;
		if(cnt > x) 
			move_outside(i), forb[i] = 1;
		else in.pb({i, step}), vis[i] = 1;
		if((int)in.size() == x * D) return 1;
		lst = cnt;
	}
	if(y != -1) forb[y] = 1;
	return 0;
}

int min_cardinality(int N) {
	srand(time(0));
	n = N, D = 0, step = 1;
	
	for(int i = 0;i < n;i++) p.pb(i);
	shuffle(all(p), rng);
	
	for(int i : p) {
		move_inside(i);
		if(press_button() > 1) 
			move_outside(i);
		else in.pb({i, step}), vis[i] = 1, D++;
	}
	
	int lo = 1, hi = n / D, ans = 1;
	while(lo <= hi) {
		step++;
		int mid = (lo + hi) / 2;
		int num = 0;
		for(int i = 0;i < n;i++) num += !(forb[i] | vis[i]);
		if((num / D) < (mid - ans)) {hi = mid - 1;continue;}
		int flag = check(mid);
		if(flag) {
			ans = mid, lo = mid + 1;
			for(int i = 0;i < n;i++) forb[i] = 0;
		} else {
			hi = mid - 1;
			while(in.back().y == step)
				move_outside(in.back().x), vis[in.back().x] = 0, in.pop_back();
		}
	}
	return ans;
}
# 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 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 1 ms 208 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 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 4 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 18 ms 320 KB Output is correct
24 Correct 9 ms 328 KB Output is correct
25 Correct 21 ms 324 KB Output is correct
26 Correct 22 ms 320 KB Output is correct
27 Correct 29 ms 320 KB Output is correct
28 Correct 7 ms 208 KB Output is correct
29 Correct 12 ms 316 KB Output is correct
30 Correct 16 ms 320 KB Output is correct
31 Correct 23 ms 312 KB Output is correct
32 Correct 18 ms 316 KB Output is correct
33 Correct 16 ms 208 KB Output is correct
34 Correct 15 ms 208 KB Output is correct
35 Correct 23 ms 316 KB Output is correct
36 Correct 12 ms 332 KB Output is correct
37 Correct 11 ms 328 KB Output is correct
38 Correct 28 ms 300 KB Output is correct
39 Correct 20 ms 324 KB Output is correct
40 Correct 11 ms 208 KB Output is correct
41 Correct 7 ms 208 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 292 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 26 ms 312 KB Output is correct
8 Correct 18 ms 328 KB Output is correct
9 Correct 36 ms 320 KB Output is correct
10 Correct 48 ms 316 KB Output is correct
11 Partially correct 44 ms 208 KB Output is partially correct
12 Correct 20 ms 336 KB Output is correct
13 Partially correct 55 ms 308 KB Output is partially correct
14 Correct 41 ms 208 KB Output is correct
15 Correct 32 ms 348 KB Output is correct
16 Correct 36 ms 316 KB Output is correct
17 Correct 32 ms 308 KB Output is correct
18 Correct 37 ms 312 KB Output is correct
19 Correct 41 ms 324 KB Output is correct
20 Correct 38 ms 308 KB Output is correct
21 Partially correct 43 ms 324 KB Output is partially correct
22 Correct 45 ms 448 KB Output is correct
23 Correct 29 ms 316 KB Output is correct
24 Correct 30 ms 208 KB Output is correct
25 Correct 26 ms 332 KB Output is correct
26 Correct 13 ms 356 KB Output is correct
27 Correct 29 ms 320 KB Output is correct
28 Correct 22 ms 328 KB Output is correct
29 Correct 34 ms 316 KB Output is correct
30 Correct 19 ms 332 KB Output is correct
31 Correct 41 ms 340 KB Output is correct
32 Correct 43 ms 308 KB Output is correct
33 Partially correct 34 ms 328 KB Output is partially correct
34 Partially correct 55 ms 328 KB Output is partially correct
35 Correct 39 ms 308 KB Output is correct
36 Correct 33 ms 316 KB Output is correct
37 Correct 52 ms 320 KB Output is correct
38 Correct 47 ms 320 KB Output is correct
39 Correct 44 ms 316 KB Output is correct
40 Correct 29 ms 308 KB Output is correct
41 Correct 43 ms 332 KB Output is correct
42 Correct 33 ms 304 KB Output is correct
43 Correct 13 ms 208 KB Output is correct
44 Correct 35 ms 208 KB Output is correct
45 Correct 28 ms 308 KB Output is correct
46 Correct 26 ms 324 KB Output is correct
47 Correct 25 ms 316 KB Output is correct
48 Correct 24 ms 324 KB Output is correct