답안 #839173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839173 2023-08-29T01:26:36 Z dolphingarlic Homework (CEOI22_homework) C++17
100 / 100
267 ms 160792 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2000001;

vector<int> graph[N];
int p[N], n = 0, type[N], sz[N], mn[N], mx[N];

void dfs(int node = 1) {
	if (!graph[node].size()) return;
	int u = graph[node][0], v = graph[node][1];
	dfs(u);
	dfs(v);
	sz[node] += sz[u] + sz[v];
	if (type[node] == 1) {  // min
		mn[node] = min(mn[u], mn[v]);
		mx[node] = mx[u] + mx[v] - 1;
	} else if (type[node] == 2) {  // max
		mn[node] = mn[u] + mn[v];
		mx[node] = max(sz[u] + mx[v], sz[v] + mx[u]);
	}
}
 
int main() {
	string s;
	cin >> s;
	int curr = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'm') {
			p[++n] = curr;
			graph[curr].push_back(n);
			curr = n;
			if (s[i + 2] == 'n') type[curr] = 1;  // min
			else type[curr] = 2;  // max
			i += 3;
		} else if (s[i] == '?') {
			p[++n] = curr;
			graph[curr].push_back(n);
			curr = n;
			mn[curr] = mx[curr] = sz[curr] = 1;
		} else curr = p[curr];
	}
	dfs();
	cout << mx[1] - mn[1] + 1;
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47268 KB Output is correct
2 Correct 21 ms 47276 KB Output is correct
3 Correct 23 ms 47272 KB Output is correct
4 Correct 21 ms 47316 KB Output is correct
5 Correct 21 ms 47284 KB Output is correct
6 Correct 23 ms 47264 KB Output is correct
7 Correct 22 ms 47276 KB Output is correct
8 Correct 22 ms 47256 KB Output is correct
9 Correct 22 ms 47272 KB Output is correct
10 Correct 24 ms 47180 KB Output is correct
11 Correct 26 ms 47288 KB Output is correct
12 Correct 21 ms 47300 KB Output is correct
13 Correct 23 ms 47236 KB Output is correct
14 Correct 22 ms 47216 KB Output is correct
15 Correct 23 ms 47292 KB Output is correct
16 Correct 23 ms 47212 KB Output is correct
17 Correct 22 ms 47240 KB Output is correct
18 Correct 22 ms 47244 KB Output is correct
19 Correct 22 ms 47292 KB Output is correct
20 Correct 25 ms 47316 KB Output is correct
21 Correct 23 ms 47292 KB Output is correct
22 Correct 22 ms 47204 KB Output is correct
23 Correct 21 ms 47188 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 22 ms 47264 KB Output is correct
27 Correct 22 ms 47280 KB Output is correct
28 Correct 24 ms 47264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47268 KB Output is correct
2 Correct 21 ms 47276 KB Output is correct
3 Correct 23 ms 47272 KB Output is correct
4 Correct 21 ms 47316 KB Output is correct
5 Correct 21 ms 47284 KB Output is correct
6 Correct 23 ms 47264 KB Output is correct
7 Correct 22 ms 47276 KB Output is correct
8 Correct 22 ms 47256 KB Output is correct
9 Correct 22 ms 47272 KB Output is correct
10 Correct 24 ms 47180 KB Output is correct
11 Correct 26 ms 47288 KB Output is correct
12 Correct 21 ms 47300 KB Output is correct
13 Correct 23 ms 47236 KB Output is correct
14 Correct 22 ms 47216 KB Output is correct
15 Correct 23 ms 47292 KB Output is correct
16 Correct 23 ms 47212 KB Output is correct
17 Correct 22 ms 47240 KB Output is correct
18 Correct 22 ms 47244 KB Output is correct
19 Correct 22 ms 47292 KB Output is correct
20 Correct 25 ms 47316 KB Output is correct
21 Correct 23 ms 47292 KB Output is correct
22 Correct 22 ms 47204 KB Output is correct
23 Correct 21 ms 47188 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 22 ms 47264 KB Output is correct
27 Correct 22 ms 47280 KB Output is correct
28 Correct 24 ms 47264 KB Output is correct
29 Correct 23 ms 47268 KB Output is correct
30 Correct 23 ms 47188 KB Output is correct
31 Correct 22 ms 47268 KB Output is correct
32 Correct 23 ms 47292 KB Output is correct
33 Correct 24 ms 47276 KB Output is correct
34 Correct 23 ms 47236 KB Output is correct
35 Correct 23 ms 47240 KB Output is correct
36 Correct 22 ms 47312 KB Output is correct
37 Correct 22 ms 47188 KB Output is correct
38 Correct 24 ms 47276 KB Output is correct
39 Correct 22 ms 47304 KB Output is correct
40 Correct 24 ms 47236 KB Output is correct
41 Correct 23 ms 47228 KB Output is correct
42 Correct 22 ms 47268 KB Output is correct
43 Correct 22 ms 47176 KB Output is correct
44 Correct 23 ms 47280 KB Output is correct
45 Correct 23 ms 47264 KB Output is correct
46 Correct 27 ms 47448 KB Output is correct
47 Correct 22 ms 47204 KB Output is correct
48 Correct 23 ms 47272 KB Output is correct
49 Correct 23 ms 47236 KB Output is correct
50 Correct 23 ms 47196 KB Output is correct
51 Correct 23 ms 47240 KB Output is correct
52 Correct 23 ms 47236 KB Output is correct
53 Correct 25 ms 47188 KB Output is correct
54 Correct 25 ms 47216 KB Output is correct
55 Correct 23 ms 47188 KB Output is correct
56 Correct 23 ms 47272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 155908 KB Output is correct
2 Correct 241 ms 160668 KB Output is correct
3 Correct 240 ms 160708 KB Output is correct
4 Correct 241 ms 160700 KB Output is correct
5 Correct 240 ms 160684 KB Output is correct
6 Correct 248 ms 160728 KB Output is correct
7 Correct 245 ms 160736 KB Output is correct
8 Correct 238 ms 160760 KB Output is correct
9 Correct 242 ms 160756 KB Output is correct
10 Correct 241 ms 160660 KB Output is correct
11 Correct 238 ms 160692 KB Output is correct
12 Correct 252 ms 160676 KB Output is correct
13 Correct 26 ms 47268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47268 KB Output is correct
2 Correct 21 ms 47276 KB Output is correct
3 Correct 23 ms 47272 KB Output is correct
4 Correct 21 ms 47316 KB Output is correct
5 Correct 21 ms 47284 KB Output is correct
6 Correct 23 ms 47264 KB Output is correct
7 Correct 22 ms 47276 KB Output is correct
8 Correct 22 ms 47256 KB Output is correct
9 Correct 22 ms 47272 KB Output is correct
10 Correct 24 ms 47180 KB Output is correct
11 Correct 26 ms 47288 KB Output is correct
12 Correct 21 ms 47300 KB Output is correct
13 Correct 23 ms 47236 KB Output is correct
14 Correct 22 ms 47216 KB Output is correct
15 Correct 23 ms 47292 KB Output is correct
16 Correct 23 ms 47212 KB Output is correct
17 Correct 22 ms 47240 KB Output is correct
18 Correct 22 ms 47244 KB Output is correct
19 Correct 22 ms 47292 KB Output is correct
20 Correct 25 ms 47316 KB Output is correct
21 Correct 23 ms 47292 KB Output is correct
22 Correct 22 ms 47204 KB Output is correct
23 Correct 21 ms 47188 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 22 ms 47264 KB Output is correct
27 Correct 22 ms 47280 KB Output is correct
28 Correct 24 ms 47264 KB Output is correct
29 Correct 23 ms 47268 KB Output is correct
30 Correct 23 ms 47188 KB Output is correct
31 Correct 22 ms 47268 KB Output is correct
32 Correct 23 ms 47292 KB Output is correct
33 Correct 24 ms 47276 KB Output is correct
34 Correct 23 ms 47236 KB Output is correct
35 Correct 23 ms 47240 KB Output is correct
36 Correct 22 ms 47312 KB Output is correct
37 Correct 22 ms 47188 KB Output is correct
38 Correct 24 ms 47276 KB Output is correct
39 Correct 22 ms 47304 KB Output is correct
40 Correct 24 ms 47236 KB Output is correct
41 Correct 23 ms 47228 KB Output is correct
42 Correct 22 ms 47268 KB Output is correct
43 Correct 22 ms 47176 KB Output is correct
44 Correct 23 ms 47280 KB Output is correct
45 Correct 23 ms 47264 KB Output is correct
46 Correct 27 ms 47448 KB Output is correct
47 Correct 22 ms 47204 KB Output is correct
48 Correct 23 ms 47272 KB Output is correct
49 Correct 23 ms 47236 KB Output is correct
50 Correct 23 ms 47196 KB Output is correct
51 Correct 23 ms 47240 KB Output is correct
52 Correct 23 ms 47236 KB Output is correct
53 Correct 25 ms 47188 KB Output is correct
54 Correct 25 ms 47216 KB Output is correct
55 Correct 23 ms 47188 KB Output is correct
56 Correct 23 ms 47272 KB Output is correct
57 Correct 22 ms 47348 KB Output is correct
58 Correct 22 ms 47308 KB Output is correct
59 Correct 23 ms 47276 KB Output is correct
60 Correct 24 ms 47272 KB Output is correct
61 Correct 24 ms 47308 KB Output is correct
62 Correct 24 ms 47324 KB Output is correct
63 Correct 23 ms 47276 KB Output is correct
64 Correct 23 ms 47360 KB Output is correct
65 Correct 23 ms 47276 KB Output is correct
66 Correct 27 ms 47436 KB Output is correct
67 Correct 23 ms 47348 KB Output is correct
68 Correct 23 ms 47276 KB Output is correct
69 Correct 23 ms 47288 KB Output is correct
70 Correct 23 ms 47264 KB Output is correct
71 Correct 24 ms 47284 KB Output is correct
72 Correct 24 ms 47316 KB Output is correct
73 Correct 23 ms 47396 KB Output is correct
74 Correct 23 ms 47316 KB Output is correct
75 Correct 23 ms 47308 KB Output is correct
76 Correct 23 ms 47292 KB Output is correct
77 Correct 23 ms 47276 KB Output is correct
78 Correct 23 ms 47316 KB Output is correct
79 Correct 26 ms 47368 KB Output is correct
80 Correct 22 ms 47384 KB Output is correct
81 Correct 24 ms 47328 KB Output is correct
82 Correct 23 ms 47308 KB Output is correct
83 Correct 23 ms 47232 KB Output is correct
84 Correct 22 ms 47328 KB Output is correct
85 Correct 23 ms 47316 KB Output is correct
86 Correct 23 ms 47272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 47268 KB Output is correct
2 Correct 21 ms 47276 KB Output is correct
3 Correct 23 ms 47272 KB Output is correct
4 Correct 21 ms 47316 KB Output is correct
5 Correct 21 ms 47284 KB Output is correct
6 Correct 23 ms 47264 KB Output is correct
7 Correct 22 ms 47276 KB Output is correct
8 Correct 22 ms 47256 KB Output is correct
9 Correct 22 ms 47272 KB Output is correct
10 Correct 24 ms 47180 KB Output is correct
11 Correct 26 ms 47288 KB Output is correct
12 Correct 21 ms 47300 KB Output is correct
13 Correct 23 ms 47236 KB Output is correct
14 Correct 22 ms 47216 KB Output is correct
15 Correct 23 ms 47292 KB Output is correct
16 Correct 23 ms 47212 KB Output is correct
17 Correct 22 ms 47240 KB Output is correct
18 Correct 22 ms 47244 KB Output is correct
19 Correct 22 ms 47292 KB Output is correct
20 Correct 25 ms 47316 KB Output is correct
21 Correct 23 ms 47292 KB Output is correct
22 Correct 22 ms 47204 KB Output is correct
23 Correct 21 ms 47188 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 22 ms 47268 KB Output is correct
26 Correct 22 ms 47264 KB Output is correct
27 Correct 22 ms 47280 KB Output is correct
28 Correct 24 ms 47264 KB Output is correct
29 Correct 23 ms 47268 KB Output is correct
30 Correct 23 ms 47188 KB Output is correct
31 Correct 22 ms 47268 KB Output is correct
32 Correct 23 ms 47292 KB Output is correct
33 Correct 24 ms 47276 KB Output is correct
34 Correct 23 ms 47236 KB Output is correct
35 Correct 23 ms 47240 KB Output is correct
36 Correct 22 ms 47312 KB Output is correct
37 Correct 22 ms 47188 KB Output is correct
38 Correct 24 ms 47276 KB Output is correct
39 Correct 22 ms 47304 KB Output is correct
40 Correct 24 ms 47236 KB Output is correct
41 Correct 23 ms 47228 KB Output is correct
42 Correct 22 ms 47268 KB Output is correct
43 Correct 22 ms 47176 KB Output is correct
44 Correct 23 ms 47280 KB Output is correct
45 Correct 23 ms 47264 KB Output is correct
46 Correct 27 ms 47448 KB Output is correct
47 Correct 22 ms 47204 KB Output is correct
48 Correct 23 ms 47272 KB Output is correct
49 Correct 23 ms 47236 KB Output is correct
50 Correct 23 ms 47196 KB Output is correct
51 Correct 23 ms 47240 KB Output is correct
52 Correct 23 ms 47236 KB Output is correct
53 Correct 25 ms 47188 KB Output is correct
54 Correct 25 ms 47216 KB Output is correct
55 Correct 23 ms 47188 KB Output is correct
56 Correct 23 ms 47272 KB Output is correct
57 Correct 248 ms 155908 KB Output is correct
58 Correct 241 ms 160668 KB Output is correct
59 Correct 240 ms 160708 KB Output is correct
60 Correct 241 ms 160700 KB Output is correct
61 Correct 240 ms 160684 KB Output is correct
62 Correct 248 ms 160728 KB Output is correct
63 Correct 245 ms 160736 KB Output is correct
64 Correct 238 ms 160760 KB Output is correct
65 Correct 242 ms 160756 KB Output is correct
66 Correct 241 ms 160660 KB Output is correct
67 Correct 238 ms 160692 KB Output is correct
68 Correct 252 ms 160676 KB Output is correct
69 Correct 26 ms 47268 KB Output is correct
70 Correct 22 ms 47348 KB Output is correct
71 Correct 22 ms 47308 KB Output is correct
72 Correct 23 ms 47276 KB Output is correct
73 Correct 24 ms 47272 KB Output is correct
74 Correct 24 ms 47308 KB Output is correct
75 Correct 24 ms 47324 KB Output is correct
76 Correct 23 ms 47276 KB Output is correct
77 Correct 23 ms 47360 KB Output is correct
78 Correct 23 ms 47276 KB Output is correct
79 Correct 27 ms 47436 KB Output is correct
80 Correct 23 ms 47348 KB Output is correct
81 Correct 23 ms 47276 KB Output is correct
82 Correct 23 ms 47288 KB Output is correct
83 Correct 23 ms 47264 KB Output is correct
84 Correct 24 ms 47284 KB Output is correct
85 Correct 24 ms 47316 KB Output is correct
86 Correct 23 ms 47396 KB Output is correct
87 Correct 23 ms 47316 KB Output is correct
88 Correct 23 ms 47308 KB Output is correct
89 Correct 23 ms 47292 KB Output is correct
90 Correct 23 ms 47276 KB Output is correct
91 Correct 23 ms 47316 KB Output is correct
92 Correct 26 ms 47368 KB Output is correct
93 Correct 22 ms 47384 KB Output is correct
94 Correct 24 ms 47328 KB Output is correct
95 Correct 23 ms 47308 KB Output is correct
96 Correct 23 ms 47232 KB Output is correct
97 Correct 22 ms 47328 KB Output is correct
98 Correct 23 ms 47316 KB Output is correct
99 Correct 23 ms 47272 KB Output is correct
100 Correct 225 ms 131384 KB Output is correct
101 Correct 229 ms 131332 KB Output is correct
102 Correct 223 ms 131384 KB Output is correct
103 Correct 220 ms 131284 KB Output is correct
104 Correct 218 ms 131452 KB Output is correct
105 Correct 236 ms 141780 KB Output is correct
106 Correct 236 ms 141812 KB Output is correct
107 Correct 251 ms 141816 KB Output is correct
108 Correct 234 ms 141696 KB Output is correct
109 Correct 239 ms 141732 KB Output is correct
110 Correct 231 ms 131444 KB Output is correct
111 Correct 228 ms 131348 KB Output is correct
112 Correct 226 ms 131368 KB Output is correct
113 Correct 235 ms 131324 KB Output is correct
114 Correct 222 ms 131368 KB Output is correct
115 Correct 247 ms 160640 KB Output is correct
116 Correct 260 ms 160744 KB Output is correct
117 Correct 249 ms 160652 KB Output is correct
118 Correct 240 ms 160680 KB Output is correct
119 Correct 239 ms 160792 KB Output is correct
120 Correct 223 ms 131292 KB Output is correct
121 Correct 223 ms 131396 KB Output is correct
122 Correct 267 ms 131568 KB Output is correct
123 Correct 240 ms 131392 KB Output is correct
124 Correct 237 ms 147028 KB Output is correct
125 Correct 233 ms 147048 KB Output is correct
126 Correct 230 ms 147008 KB Output is correct
127 Correct 227 ms 146932 KB Output is correct
128 Correct 122 ms 91324 KB Output is correct
129 Correct 121 ms 91392 KB Output is correct
130 Correct 121 ms 91288 KB Output is correct
131 Correct 24 ms 47316 KB Output is correct