답안 #947740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947740 2024-03-17T01:19:20 Z biank 드문 곤충 (IOI22_insects) C++17
100 / 100
37 ms 1872 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)

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 oldK = 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 = oldK;
	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;
	int l = 0, r = N / T + 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (check(m, K)) {
			l = m;
		} else {
			r = m;
		}
	}
	
	return l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 856 KB Output is correct
9 Correct 3 ms 444 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 2 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 856 KB Output is correct
9 Correct 3 ms 444 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 2 ms 444 KB Output is correct
23 Correct 8 ms 1112 KB Output is correct
24 Correct 9 ms 884 KB Output is correct
25 Correct 13 ms 708 KB Output is correct
26 Correct 13 ms 960 KB Output is correct
27 Correct 11 ms 888 KB Output is correct
28 Correct 9 ms 856 KB Output is correct
29 Correct 12 ms 628 KB Output is correct
30 Correct 14 ms 604 KB Output is correct
31 Correct 12 ms 856 KB Output is correct
32 Correct 11 ms 1112 KB Output is correct
33 Correct 10 ms 876 KB Output is correct
34 Correct 10 ms 1116 KB Output is correct
35 Correct 11 ms 856 KB Output is correct
36 Correct 12 ms 624 KB Output is correct
37 Correct 12 ms 1112 KB Output is correct
38 Correct 13 ms 868 KB Output is correct
39 Correct 17 ms 1116 KB Output is correct
40 Correct 12 ms 1112 KB Output is correct
41 Correct 9 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 20 ms 1248 KB Output is correct
8 Correct 18 ms 1404 KB Output is correct
9 Correct 20 ms 1392 KB Output is correct
10 Correct 28 ms 1112 KB Output is correct
11 Correct 24 ms 1164 KB Output is correct
12 Correct 23 ms 1116 KB Output is correct
13 Correct 27 ms 856 KB Output is correct
14 Correct 31 ms 680 KB Output is correct
15 Correct 20 ms 1232 KB Output is correct
16 Correct 20 ms 1112 KB Output is correct
17 Correct 25 ms 988 KB Output is correct
18 Correct 25 ms 1216 KB Output is correct
19 Correct 26 ms 884 KB Output is correct
20 Correct 27 ms 656 KB Output is correct
21 Correct 28 ms 1152 KB Output is correct
22 Correct 24 ms 760 KB Output is correct
23 Correct 26 ms 856 KB Output is correct
24 Correct 28 ms 1116 KB Output is correct
25 Correct 24 ms 980 KB Output is correct
26 Correct 20 ms 1236 KB Output is correct
27 Correct 23 ms 976 KB Output is correct
28 Correct 25 ms 668 KB Output is correct
29 Correct 26 ms 600 KB Output is correct
30 Correct 23 ms 920 KB Output is correct
31 Correct 29 ms 1616 KB Output is correct
32 Correct 26 ms 856 KB Output is correct
33 Correct 37 ms 1124 KB Output is correct
34 Correct 27 ms 1368 KB Output is correct
35 Correct 21 ms 1476 KB Output is correct
36 Correct 20 ms 968 KB Output is correct
37 Correct 26 ms 708 KB Output is correct
38 Correct 24 ms 856 KB Output is correct
39 Correct 31 ms 1872 KB Output is correct
40 Correct 24 ms 1624 KB Output is correct
41 Correct 25 ms 1632 KB Output is correct
42 Correct 32 ms 864 KB Output is correct
43 Correct 5 ms 600 KB Output is correct
44 Correct 25 ms 1368 KB Output is correct
45 Correct 19 ms 1000 KB Output is correct
46 Correct 23 ms 632 KB Output is correct
47 Correct 23 ms 1384 KB Output is correct
48 Correct 24 ms 1460 KB Output is correct