Submission #630047

# Submission time Handle Problem Language Result Execution time Memory
630047 2022-08-15T14:58:51 Z _Avocado_ Rarest Insects (IOI22_insects) C++17
96.54 / 100
61 ms 432 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;

int min_cardinality(int n){
	vector<int>unique(n);
	int unique_cnt = 0;
	for(int i = 0; i<n; ++i){
		move_inside(i);
		int q = press_button();
		if(q == 1){
			unique[i] = 1;
			++unique_cnt;
		}
		else move_outside(i);
	}
	
	int r = n/unique_cnt+1;
	int l = 0;
	vector<int>cur;
	set<int>in_box;
	for(int i = 0; i<n; ++i){
		if(!unique[i]) cur.push_back(i);
		else in_box.insert(i);
	}
	
	while(r-l > 1){
		int m = (r+l)/2;
		//cout<<"m "<<m<<endl;
		vector<int>high, low;
		for(int i = 0; i<cur.size(); ++i){
			if(in_box.size() == m*unique_cnt){
				high.push_back(cur[i]);
				continue;
			}
			move_inside(cur[i]);
			int q = press_button();
			if(q > m){
				high.push_back(cur[i]);
				move_outside(cur[i]);
			}
			else{
				low.push_back(cur[i]);
				in_box.insert(cur[i]);
			}
		}
	
		if(in_box.size() != m*unique_cnt){
			for(int i = 0; i<cur.size(); ++i){
				move_outside(cur[i]);
				in_box.erase(cur[i]);
			}
			cur = low;
			r = m;
		}
		else{
			cur = high;
			l = m;
		}
	}
			
	return l;	

}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 0; i<cur.size(); ++i){
      |                  ~^~~~~~~~~~~
insects.cpp:32:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |    if(in_box.size() == m*unique_cnt){
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp:48:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |   if(in_box.size() != m*unique_cnt){
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    for(int i = 0; i<cur.size(); ++i){
      |                   ~^~~~~~~~~~~
# 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 6 ms 312 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 304 KB Output is correct
13 Correct 5 ms 296 KB Output is correct
14 Correct 6 ms 308 KB Output is correct
15 Correct 4 ms 300 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 5 ms 296 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 5 ms 336 KB Output is correct
21 Correct 3 ms 300 KB Output is correct
22 Correct 2 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 6 ms 312 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 5 ms 304 KB Output is correct
13 Correct 5 ms 296 KB Output is correct
14 Correct 6 ms 308 KB Output is correct
15 Correct 4 ms 300 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 5 ms 296 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 5 ms 336 KB Output is correct
21 Correct 3 ms 300 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 12 ms 300 KB Output is correct
24 Correct 7 ms 328 KB Output is correct
25 Correct 20 ms 316 KB Output is correct
26 Correct 28 ms 208 KB Output is correct
27 Correct 24 ms 292 KB Output is correct
28 Correct 9 ms 292 KB Output is correct
29 Correct 21 ms 356 KB Output is correct
30 Correct 22 ms 308 KB Output is correct
31 Correct 24 ms 328 KB Output is correct
32 Correct 24 ms 288 KB Output is correct
33 Correct 29 ms 292 KB Output is correct
34 Correct 17 ms 308 KB Output is correct
35 Correct 18 ms 420 KB Output is correct
36 Correct 17 ms 296 KB Output is correct
37 Correct 28 ms 292 KB Output is correct
38 Correct 29 ms 292 KB Output is correct
39 Correct 18 ms 208 KB Output is correct
40 Correct 23 ms 320 KB Output is correct
41 Correct 9 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 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 37 ms 288 KB Output is correct
8 Correct 8 ms 300 KB Output is correct
9 Correct 55 ms 304 KB Output is correct
10 Correct 61 ms 432 KB Output is correct
11 Partially correct 43 ms 300 KB Output is partially correct
12 Correct 18 ms 288 KB Output is correct
13 Partially correct 49 ms 344 KB Output is partially correct
14 Partially correct 24 ms 300 KB Output is partially correct
15 Correct 40 ms 380 KB Output is correct
16 Correct 49 ms 304 KB Output is correct
17 Correct 38 ms 328 KB Output is correct
18 Correct 57 ms 292 KB Output is correct
19 Correct 45 ms 288 KB Output is correct
20 Correct 38 ms 300 KB Output is correct
21 Correct 51 ms 364 KB Output is correct
22 Correct 58 ms 300 KB Output is correct
23 Correct 48 ms 296 KB Output is correct
24 Correct 28 ms 288 KB Output is correct
25 Correct 32 ms 288 KB Output is correct
26 Correct 20 ms 328 KB Output is correct
27 Correct 35 ms 336 KB Output is correct
28 Correct 34 ms 300 KB Output is correct
29 Correct 25 ms 304 KB Output is correct
30 Correct 52 ms 300 KB Output is correct
31 Correct 49 ms 360 KB Output is correct
32 Correct 59 ms 284 KB Output is correct
33 Partially correct 47 ms 432 KB Output is partially correct
34 Partially correct 45 ms 328 KB Output is partially correct
35 Partially correct 55 ms 364 KB Output is partially correct
36 Correct 49 ms 300 KB Output is correct
37 Correct 51 ms 336 KB Output is correct
38 Correct 55 ms 304 KB Output is correct
39 Correct 41 ms 304 KB Output is correct
40 Correct 41 ms 328 KB Output is correct
41 Correct 51 ms 304 KB Output is correct
42 Partially correct 33 ms 428 KB Output is partially correct
43 Partially correct 15 ms 304 KB Output is partially correct
44 Partially correct 27 ms 372 KB Output is partially correct
45 Correct 55 ms 284 KB Output is correct
46 Correct 18 ms 344 KB Output is correct
47 Correct 22 ms 328 KB Output is correct
48 Correct 31 ms 284 KB Output is correct