Submission #629629

# Submission time Handle Problem Language Result Execution time Memory
629629 2022-08-14T19:28:56 Z study Rarest Insects (IOI22_insects) C++17
100 / 100
60 ms 412 KB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
 
int min_cardinality(int N) {
	bitset<2000> inside;
	int nbElems = 0;
	for (int i=0; i<N; ++i){
		move_inside(i);
		if (i != 0){
			int maxFreq = press_button();
			if (maxFreq > 1) move_outside(i);
			else{
				++nbElems;
				inside[i] = true;
			}
		}
		else{
			++nbElems;
			inside[i] = true;
		}
	}
	if (nbElems == 1) return N;
	if (nbElems == N) return 1;
	int in = nbElems, crt = 1;
	int deb = 2, fin = N/nbElems, ans = 1;
	vector<int> last;
	while (deb <= fin){
		int mid = fin-(fin-deb)/2;
		if (crt > mid) mid = deb+(fin-deb)/2;
		bool ok = false;
		if (crt > mid){
			for (int i=0; i<crt-mid; ++i){
				if (last.empty()) break;
				inside[last.back()] = false;
				move_outside(last.back());
				last.pop_back();
				in--;
			}
			bool yes = false;
			int cnt = 0;
			while (!last.empty()){
				int sqrt_siz = sqrt((int)last.size());
				if (cnt%40 == 0 and press_button() <= mid){
					yes = true;
					break;
				}
				++cnt;
				int l = last.back();
				move_outside(l);
				inside[l] = false;
				last.pop_back();
				in--;
			}
			if (in == nbElems*mid and yes){
				ok = true;
			}
			crt = mid;
		}
		else last.clear();
		int delta = mid-crt;
		vector<int> outside;
		if (!ok){
			for (int i=0; i<N; ++i){
				if (!inside[i]){
					move_inside(i);
					--delta;
					++in;
					if (delta >= 0){
						inside[i] = true;
						last.emplace_back(i);
						continue;
					}
					crt = press_button();
					if (in == mid*nbElems and crt == mid){
						ok = true;
						inside[i] = true;
						last.emplace_back(i);
						break;
					}
					if (crt > mid){
						outside.emplace_back(i);
						move_outside(i);
						--in;
						--crt;
					}
					else{
						inside[i] = true;
						last.emplace_back(i);
					}
				}
			}
		}
		if (ok){
			crt = mid;
			ans = mid;
			deb = mid+1;
		}
		else{
			for (int i:outside) inside[i] = true;
			fin = mid-1;
		}
		crt = mid;
	}
	return ans;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:43:9: warning: unused variable 'sqrt_siz' [-Wunused-variable]
   43 |     int sqrt_siz = sqrt((int)last.size());
      |         ^~~~~~~~
# 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 0 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 2 ms 208 KB Output is correct
9 Correct 6 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 4 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 8 ms 208 KB Output is correct
21 Correct 4 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 0 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 2 ms 208 KB Output is correct
9 Correct 6 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 4 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 8 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 19 ms 208 KB Output is correct
26 Correct 23 ms 296 KB Output is correct
27 Correct 16 ms 208 KB Output is correct
28 Correct 11 ms 208 KB Output is correct
29 Correct 19 ms 296 KB Output is correct
30 Correct 11 ms 296 KB Output is correct
31 Correct 25 ms 276 KB Output is correct
32 Correct 22 ms 208 KB Output is correct
33 Correct 25 ms 300 KB Output is correct
34 Correct 17 ms 328 KB Output is correct
35 Correct 24 ms 276 KB Output is correct
36 Correct 25 ms 280 KB Output is correct
37 Correct 27 ms 276 KB Output is correct
38 Correct 20 ms 208 KB Output is correct
39 Correct 20 ms 208 KB Output is correct
40 Correct 15 ms 284 KB Output is correct
41 Correct 9 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 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 1 ms 208 KB Output is correct
7 Correct 19 ms 208 KB Output is correct
8 Correct 21 ms 208 KB Output is correct
9 Correct 49 ms 280 KB Output is correct
10 Correct 60 ms 280 KB Output is correct
11 Correct 36 ms 288 KB Output is correct
12 Correct 23 ms 288 KB Output is correct
13 Correct 35 ms 284 KB Output is correct
14 Correct 55 ms 280 KB Output is correct
15 Correct 28 ms 208 KB Output is correct
16 Correct 47 ms 280 KB Output is correct
17 Correct 38 ms 208 KB Output is correct
18 Correct 44 ms 280 KB Output is correct
19 Correct 42 ms 284 KB Output is correct
20 Correct 45 ms 208 KB Output is correct
21 Correct 44 ms 408 KB Output is correct
22 Correct 43 ms 292 KB Output is correct
23 Correct 38 ms 208 KB Output is correct
24 Correct 43 ms 208 KB Output is correct
25 Correct 26 ms 284 KB Output is correct
26 Correct 20 ms 208 KB Output is correct
27 Correct 55 ms 208 KB Output is correct
28 Correct 29 ms 284 KB Output is correct
29 Correct 46 ms 208 KB Output is correct
30 Correct 59 ms 280 KB Output is correct
31 Correct 40 ms 288 KB Output is correct
32 Correct 42 ms 208 KB Output is correct
33 Correct 38 ms 284 KB Output is correct
34 Correct 44 ms 280 KB Output is correct
35 Correct 57 ms 292 KB Output is correct
36 Correct 34 ms 208 KB Output is correct
37 Correct 41 ms 288 KB Output is correct
38 Correct 41 ms 276 KB Output is correct
39 Correct 37 ms 288 KB Output is correct
40 Correct 35 ms 280 KB Output is correct
41 Correct 20 ms 292 KB Output is correct
42 Correct 24 ms 208 KB Output is correct
43 Correct 10 ms 208 KB Output is correct
44 Correct 39 ms 412 KB Output is correct
45 Correct 23 ms 284 KB Output is correct
46 Correct 32 ms 208 KB Output is correct
47 Correct 25 ms 288 KB Output is correct
48 Correct 29 ms 276 KB Output is correct