답안 #629620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629620 2022-08-14T19:04:47 Z study 드문 곤충 (IOI22_insects) C++17
100 / 100
57 ms 304 KB
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
 
int min_cardinality(int N) {
	vector<int> a(N);
	for (int i=0; i<N; ++i){
		a[i] = i;
	}
//	random_shuffle(a.begin(),a.end());
	bitset<2000> inside;
	int nbElems = 0;
	for (int i=0; i<N; ++i){
		move_inside(a[i]);
		if (i != 0){
			int maxFreq = press_button();
			if (maxFreq > 1) move_outside(a[i]);
			else{
				++nbElems;
				inside[a[i]] = true;
//				cout << a[i] << endl;
			}
		}
		else{
			++nbElems;
			inside[a[i]] = true;
//			cout << a[i] << endl;
		}
	}
	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:last){
				inside[i] = false;
				in--;
				move_outside(i);
			}
*/			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;
//			random_shuffle(last.begin(),last.end());
			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 (last.empty() and press_button() > mid) return ans;
			if (in == nbElems*mid and yes){
				ok = true;
			}
			crt = mid;
		}
		else last.clear();
		int delta = mid-crt;
		vector<int> outside;
		if (!ok){
//			random_shuffle(a.begin(),a.end());
			for (int i=0; i<N; ++i){
				if (!inside[a[i]]){
					move_inside(a[i]);
					--delta;
					++in;
					if (delta >= 0){
						inside[a[i]] = true;
						last.emplace_back(a[i]);
						continue;
					}
					crt = press_button();
					if (in == mid*nbElems and crt == mid){
						ok = true;
						inside[a[i]] = true;
						last.emplace_back(a[i]);
//						cout << crt << ' ' << in << endl;
						break;
					}
					if (crt > mid){
						outside.emplace_back(a[i]);
						move_outside(a[i]);
						--in;
						--crt;
					}
					else{
//						cout << a[i] << ' ' << in << endl;
						inside[a[i]] = true;
						last.emplace_back(a[i]);
					}
				}
			}
		}
//		cout << mid << endl;
		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:56:9: warning: unused variable 'sqrt_siz' [-Wunused-variable]
   56 |     int sqrt_siz = sqrt((int)last.size());
      |         ^~~~~~~~
# 결과 실행 시간 메모리 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 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 300 KB Output is correct
13 Correct 4 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 6 ms 300 KB Output is correct
18 Correct 5 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 1 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 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 4 ms 300 KB Output is correct
13 Correct 4 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 6 ms 300 KB Output is correct
18 Correct 5 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 1 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 19 ms 288 KB Output is correct
26 Correct 18 ms 304 KB Output is correct
27 Correct 19 ms 208 KB Output is correct
28 Correct 7 ms 208 KB Output is correct
29 Correct 23 ms 296 KB Output is correct
30 Correct 24 ms 208 KB Output is correct
31 Correct 14 ms 208 KB Output is correct
32 Correct 15 ms 208 KB Output is correct
33 Correct 19 ms 208 KB Output is correct
34 Correct 19 ms 208 KB Output is correct
35 Correct 18 ms 208 KB Output is correct
36 Correct 22 ms 208 KB Output is correct
37 Correct 23 ms 288 KB Output is correct
38 Correct 22 ms 300 KB Output is correct
39 Correct 21 ms 208 KB Output is correct
40 Correct 13 ms 208 KB Output is correct
41 Correct 11 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 19 ms 208 KB Output is correct
8 Correct 19 ms 208 KB Output is correct
9 Correct 35 ms 284 KB Output is correct
10 Correct 41 ms 208 KB Output is correct
11 Correct 42 ms 296 KB Output is correct
12 Correct 20 ms 300 KB Output is correct
13 Correct 37 ms 304 KB Output is correct
14 Correct 51 ms 208 KB Output is correct
15 Correct 30 ms 208 KB Output is correct
16 Correct 33 ms 208 KB Output is correct
17 Correct 30 ms 208 KB Output is correct
18 Correct 44 ms 208 KB Output is correct
19 Correct 44 ms 208 KB Output is correct
20 Correct 38 ms 208 KB Output is correct
21 Correct 51 ms 296 KB Output is correct
22 Correct 41 ms 208 KB Output is correct
23 Correct 53 ms 296 KB Output is correct
24 Correct 35 ms 208 KB Output is correct
25 Correct 30 ms 208 KB Output is correct
26 Correct 15 ms 208 KB Output is correct
27 Correct 46 ms 208 KB Output is correct
28 Correct 26 ms 208 KB Output is correct
29 Correct 46 ms 288 KB Output is correct
30 Correct 57 ms 208 KB Output is correct
31 Correct 38 ms 208 KB Output is correct
32 Correct 55 ms 208 KB Output is correct
33 Correct 46 ms 208 KB Output is correct
34 Correct 39 ms 300 KB Output is correct
35 Correct 37 ms 304 KB Output is correct
36 Correct 37 ms 292 KB Output is correct
37 Correct 50 ms 288 KB Output is correct
38 Correct 21 ms 208 KB Output is correct
39 Correct 34 ms 292 KB Output is correct
40 Correct 32 ms 288 KB Output is correct
41 Correct 47 ms 284 KB Output is correct
42 Correct 38 ms 208 KB Output is correct
43 Correct 11 ms 208 KB Output is correct
44 Correct 28 ms 288 KB Output is correct
45 Correct 22 ms 288 KB Output is correct
46 Correct 22 ms 300 KB Output is correct
47 Correct 29 ms 208 KB Output is correct
48 Correct 24 ms 208 KB Output is correct