답안 #630049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630049 2022-08-15T15:01:59 Z _Avocado_ 드문 곤충 (IOI22_insects) C++17
96.54 / 100
64 ms 592 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;
		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:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i = 0; i<cur.size(); ++i){
      |                  ~^~~~~~~~~~~
insects.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |    if(in_box.size() == m*unique_cnt){
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp:47:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |   if(in_box.size() != m*unique_cnt){
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int i = 0; i<cur.size(); ++i){
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 336 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 304 KB Output is correct
13 Correct 4 ms 296 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 3 ms 300 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 336 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 304 KB Output is correct
13 Correct 4 ms 296 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 3 ms 300 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 15 ms 296 KB Output is correct
24 Correct 9 ms 328 KB Output is correct
25 Correct 20 ms 292 KB Output is correct
26 Correct 28 ms 316 KB Output is correct
27 Correct 25 ms 300 KB Output is correct
28 Correct 8 ms 300 KB Output is correct
29 Correct 28 ms 208 KB Output is correct
30 Correct 28 ms 336 KB Output is correct
31 Correct 18 ms 300 KB Output is correct
32 Correct 23 ms 296 KB Output is correct
33 Correct 18 ms 328 KB Output is correct
34 Correct 19 ms 296 KB Output is correct
35 Correct 19 ms 320 KB Output is correct
36 Correct 21 ms 324 KB Output is correct
37 Correct 26 ms 300 KB Output is correct
38 Correct 21 ms 208 KB Output is correct
39 Correct 23 ms 208 KB Output is correct
40 Correct 13 ms 340 KB Output is correct
41 Correct 8 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 33 ms 328 KB Output is correct
8 Correct 20 ms 296 KB Output is correct
9 Correct 45 ms 420 KB Output is correct
10 Correct 58 ms 296 KB Output is correct
11 Partially correct 35 ms 328 KB Output is partially correct
12 Correct 28 ms 300 KB Output is correct
13 Partially correct 45 ms 352 KB Output is partially correct
14 Partially correct 29 ms 296 KB Output is partially correct
15 Correct 38 ms 308 KB Output is correct
16 Correct 36 ms 296 KB Output is correct
17 Correct 24 ms 292 KB Output is correct
18 Correct 51 ms 328 KB Output is correct
19 Correct 47 ms 420 KB Output is correct
20 Correct 40 ms 288 KB Output is correct
21 Correct 54 ms 328 KB Output is correct
22 Correct 47 ms 352 KB Output is correct
23 Correct 37 ms 316 KB Output is correct
24 Correct 34 ms 336 KB Output is correct
25 Correct 32 ms 360 KB Output is correct
26 Correct 18 ms 328 KB Output is correct
27 Correct 46 ms 372 KB Output is correct
28 Correct 42 ms 328 KB Output is correct
29 Correct 58 ms 592 KB Output is correct
30 Correct 64 ms 292 KB Output is correct
31 Correct 50 ms 328 KB Output is correct
32 Correct 58 ms 284 KB Output is correct
33 Partially correct 51 ms 328 KB Output is partially correct
34 Partially correct 41 ms 328 KB Output is partially correct
35 Partially correct 60 ms 300 KB Output is partially correct
36 Correct 35 ms 288 KB Output is correct
37 Correct 49 ms 368 KB Output is correct
38 Correct 49 ms 368 KB Output is correct
39 Correct 42 ms 368 KB Output is correct
40 Correct 36 ms 424 KB Output is correct
41 Correct 42 ms 300 KB Output is correct
42 Partially correct 64 ms 332 KB Output is partially correct
43 Partially correct 11 ms 312 KB Output is partially correct
44 Partially correct 41 ms 304 KB Output is partially correct
45 Correct 37 ms 296 KB Output is correct
46 Correct 28 ms 296 KB Output is correct
47 Correct 24 ms 300 KB Output is correct
48 Correct 25 ms 288 KB Output is correct