답안 #837154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837154 2023-08-25T03:39:15 Z biank 드문 곤충 (IOI22_insects) C++17
100 / 100
46 ms 712 KB
#include <bits/stdc++.h>

using namespace std;

#define ALL(x) x.begin(), x.end()
#define DBGY(x) cerr << #x << ": " << x << ", ";
#define DBG(x) cerr << #x << ": " << x << endl;

void move_inside(int i);
void move_outside(int i);
int press_button();

stack <int> in;
set <int> s;
int T;

bool check(int m, int &K) {
	int old_k = K;
	vector <int> v(ALL(s));
	random_shuffle(ALL(v));
	for (int i:v) {
		move_inside(i);
		if (press_button() <= m) {
			in.push(i);
			if (++K == m*T) {
				while (!in.empty()) {
					s.erase(in.top());
					in.pop();
				}
				return true;
			}
		} else {
			move_outside(i);
		}
	}
	s.clear();
	while (!in.empty()) {
		s.insert(in.top());
		move_outside(in.top());
		in.pop();
	}
	K = old_k;
	return false;
}

int min_cardinality(int N) {
	srand(time(0));
	move_inside(0);
	in.push(0);
	s.insert(0);
	T = 1;
	for (int i=1; i<N; i++) {
		s.insert(i);
		move_inside(i);
		if (press_button() == 1) {
			in.push(i);
			T++;
		} else {
			move_outside(i);
		}
	}
	while (!in.empty()) {
		move_outside(in.top());
		in.pop();
	}
	
	int K = 0, l = 0, r = N/T+1;
	
	while (l+1 < r) {
		int m = (l+r)/2;
		if (check(m, K)) {
			l = m;
		} else {
			r = m;
		}
	}
	
	return l;
}
# 결과 실행 시간 메모리 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 4 ms 308 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 4 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 208 KB Output is correct
21 Correct 4 ms 208 KB Output is correct
22 Correct 3 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 4 ms 308 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 4 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 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 12 ms 336 KB Output is correct
24 Correct 18 ms 336 KB Output is correct
25 Correct 13 ms 336 KB Output is correct
26 Correct 22 ms 336 KB Output is correct
27 Correct 21 ms 356 KB Output is correct
28 Correct 13 ms 332 KB Output is correct
29 Correct 26 ms 336 KB Output is correct
30 Correct 26 ms 336 KB Output is correct
31 Correct 15 ms 336 KB Output is correct
32 Correct 20 ms 332 KB Output is correct
33 Correct 23 ms 208 KB Output is correct
34 Correct 15 ms 336 KB Output is correct
35 Correct 16 ms 336 KB Output is correct
36 Correct 22 ms 336 KB Output is correct
37 Correct 19 ms 308 KB Output is correct
38 Correct 18 ms 208 KB Output is correct
39 Correct 19 ms 336 KB Output is correct
40 Correct 20 ms 328 KB Output is correct
41 Correct 8 ms 336 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 26 ms 336 KB Output is correct
8 Correct 32 ms 328 KB Output is correct
9 Correct 30 ms 352 KB Output is correct
10 Correct 31 ms 376 KB Output is correct
11 Correct 31 ms 336 KB Output is correct
12 Correct 43 ms 336 KB Output is correct
13 Correct 46 ms 328 KB Output is correct
14 Correct 46 ms 384 KB Output is correct
15 Correct 28 ms 456 KB Output is correct
16 Correct 26 ms 336 KB Output is correct
17 Correct 38 ms 336 KB Output is correct
18 Correct 18 ms 336 KB Output is correct
19 Correct 38 ms 712 KB Output is correct
20 Correct 31 ms 316 KB Output is correct
21 Correct 37 ms 336 KB Output is correct
22 Correct 37 ms 376 KB Output is correct
23 Correct 45 ms 384 KB Output is correct
24 Correct 40 ms 456 KB Output is correct
25 Correct 43 ms 364 KB Output is correct
26 Correct 28 ms 352 KB Output is correct
27 Correct 31 ms 336 KB Output is correct
28 Correct 18 ms 464 KB Output is correct
29 Correct 38 ms 352 KB Output is correct
30 Correct 31 ms 376 KB Output is correct
31 Correct 29 ms 332 KB Output is correct
32 Correct 45 ms 336 KB Output is correct
33 Correct 38 ms 348 KB Output is correct
34 Correct 41 ms 384 KB Output is correct
35 Correct 32 ms 308 KB Output is correct
36 Correct 38 ms 336 KB Output is correct
37 Correct 27 ms 456 KB Output is correct
38 Correct 42 ms 308 KB Output is correct
39 Correct 37 ms 360 KB Output is correct
40 Correct 34 ms 388 KB Output is correct
41 Correct 32 ms 336 KB Output is correct
42 Correct 40 ms 344 KB Output is correct
43 Correct 13 ms 316 KB Output is correct
44 Correct 27 ms 336 KB Output is correct
45 Correct 28 ms 336 KB Output is correct
46 Correct 41 ms 456 KB Output is correct
47 Correct 45 ms 336 KB Output is correct
48 Correct 31 ms 320 KB Output is correct