Submission #630643

# Submission time Handle Problem Language Result Execution time Memory
630643 2022-08-16T18:02:02 Z errorgorn Rarest Insects (IOI22_insects) C++17
100 / 100
61 ms 444 KB
#include "insects.h"
 
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
 
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
 
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
#define in move_inside
#define out move_outside
#define get press_button
 
signed min_cardinality(signed n) {
	int num=0;
 
	vector<int> v,rem;
	rep(x,0,n){
		in(x);
		if (get()==2){
			rem.pub(x);
			out(x);
		}
		else{
			v.pub(x);
			num++;
		}
	}
	for (auto it:v) out(it);
	v.clear();
 
	int ans=1;
	while (true){
		int best=1e9;
		int h=-1;
		rep(x,1,sz(rem)/num+1){
			int temp=max(num*x-1,sz(rem)-num*x);
			if (temp<best){
				best=temp;
				h=x;
			}
		}
 
		if (h==-1) break;
 		
		vector<int> small,big;
		vector<int> v;
		
		int oth=sz(rem);
		
		shuffle(all(rem),rng);
		
		for (auto it:rem){
			if (sz(small)==h*num){
				big.pub(it);
			}
			else{
				in(it);
				if (get()==h+1){
					big.pub(it);
					out(it);
				}
				else{
					small.pub(it);
					v.pub(it);
				}
			}
			
			oth--;
		}
 
		//cout<<sz(small)<<" "<<sz(big)<<endl;
		if (sz(small)==h*num){
			ans+=h;
			rem=big;
		}
		else{
			rem=small;
		}
 
		for (auto it:v) out(it);
	}
 
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 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 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 304 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 4 ms 336 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 304 KB Output is correct
19 Correct 5 ms 308 KB Output is correct
20 Correct 6 ms 308 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 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 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 5 ms 304 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 4 ms 336 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 304 KB Output is correct
19 Correct 5 ms 308 KB Output is correct
20 Correct 6 ms 308 KB Output is correct
21 Correct 2 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 18 ms 424 KB Output is correct
24 Correct 11 ms 308 KB Output is correct
25 Correct 23 ms 208 KB Output is correct
26 Correct 24 ms 324 KB Output is correct
27 Correct 22 ms 308 KB Output is correct
28 Correct 12 ms 208 KB Output is correct
29 Correct 22 ms 312 KB Output is correct
30 Correct 30 ms 312 KB Output is correct
31 Correct 19 ms 308 KB Output is correct
32 Correct 19 ms 308 KB Output is correct
33 Correct 21 ms 308 KB Output is correct
34 Correct 21 ms 208 KB Output is correct
35 Correct 28 ms 304 KB Output is correct
36 Correct 27 ms 308 KB Output is correct
37 Correct 26 ms 324 KB Output is correct
38 Correct 19 ms 424 KB Output is correct
39 Correct 22 ms 312 KB Output is correct
40 Correct 16 ms 308 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 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 32 ms 428 KB Output is correct
8 Correct 24 ms 320 KB Output is correct
9 Correct 38 ms 316 KB Output is correct
10 Correct 49 ms 316 KB Output is correct
11 Correct 38 ms 320 KB Output is correct
12 Correct 30 ms 316 KB Output is correct
13 Correct 32 ms 348 KB Output is correct
14 Correct 50 ms 320 KB Output is correct
15 Correct 43 ms 316 KB Output is correct
16 Correct 47 ms 308 KB Output is correct
17 Correct 25 ms 336 KB Output is correct
18 Correct 40 ms 320 KB Output is correct
19 Correct 44 ms 324 KB Output is correct
20 Correct 43 ms 304 KB Output is correct
21 Correct 50 ms 444 KB Output is correct
22 Correct 57 ms 332 KB Output is correct
23 Correct 29 ms 328 KB Output is correct
24 Correct 45 ms 324 KB Output is correct
25 Correct 31 ms 324 KB Output is correct
26 Correct 18 ms 312 KB Output is correct
27 Correct 40 ms 312 KB Output is correct
28 Correct 40 ms 312 KB Output is correct
29 Correct 41 ms 336 KB Output is correct
30 Correct 25 ms 316 KB Output is correct
31 Correct 61 ms 328 KB Output is correct
32 Correct 46 ms 304 KB Output is correct
33 Correct 48 ms 312 KB Output is correct
34 Correct 57 ms 332 KB Output is correct
35 Correct 37 ms 336 KB Output is correct
36 Correct 44 ms 316 KB Output is correct
37 Correct 49 ms 328 KB Output is correct
38 Correct 40 ms 320 KB Output is correct
39 Correct 30 ms 320 KB Output is correct
40 Correct 39 ms 316 KB Output is correct
41 Correct 41 ms 316 KB Output is correct
42 Correct 50 ms 328 KB Output is correct
43 Correct 13 ms 208 KB Output is correct
44 Correct 37 ms 348 KB Output is correct
45 Correct 42 ms 312 KB Output is correct
46 Correct 14 ms 348 KB Output is correct
47 Correct 24 ms 312 KB Output is correct
48 Correct 25 ms 308 KB Output is correct