답안 #966913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966913 2024-04-20T15:28:46 Z yellowtoad Homework (CEOI22_homework) C++17
100 / 100
306 ms 163016 KB
#include <iostream>
#include <vector>
#define f first
#define s second
using namespace std;

string s;
int op[2000010], cnt, n;
pair<int,int> node[2000010];
vector<int> edge[2000010], stk;

void dfs(int u) {
	for (int i = 0; i < edge[u].size(); i++) dfs(edge[u][i]);
	if (edge[u].size() == 2) {
		if (op[u]) node[u] = {min(node[edge[u][0]].f,node[edge[u][1]].f),node[edge[u][0]].s+node[edge[u][1]].s+1};
		else node[u] = {node[edge[u][0]].f+node[edge[u][1]].f+1,min(node[edge[u][0]].s,node[edge[u][1]].s)};
	} else n++;
}

int main() {
	cin >> s;
	stk.push_back(0);
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'm') {
			++cnt;
			if (s[i+1] == 'a') op[cnt] = 1;
			edge[stk.back()].push_back(cnt);
			stk.push_back(cnt);
			i += 3;
		} else if (s[i] == '?') edge[stk.back()].push_back(++cnt);
		else if (s[i] == ')') stk.pop_back();
	}
	dfs(1);
	cout << n-node[1].f-node[1].s << endl;
}

Compilation message

Main.cpp: In function 'void dfs(int)':
Main.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0; i < edge[u].size(); i++) dfs(edge[u][i]);
      |                  ~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i = 0; i < s.length(); i++) {
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47700 KB Output is correct
2 Correct 13 ms 47704 KB Output is correct
3 Correct 12 ms 47704 KB Output is correct
4 Correct 12 ms 47708 KB Output is correct
5 Correct 11 ms 47708 KB Output is correct
6 Correct 11 ms 47708 KB Output is correct
7 Correct 12 ms 47808 KB Output is correct
8 Correct 12 ms 47704 KB Output is correct
9 Correct 12 ms 47704 KB Output is correct
10 Correct 11 ms 47708 KB Output is correct
11 Correct 11 ms 47708 KB Output is correct
12 Correct 11 ms 47708 KB Output is correct
13 Correct 10 ms 47708 KB Output is correct
14 Correct 11 ms 47708 KB Output is correct
15 Correct 11 ms 47780 KB Output is correct
16 Correct 12 ms 47764 KB Output is correct
17 Correct 10 ms 47704 KB Output is correct
18 Correct 11 ms 47708 KB Output is correct
19 Correct 11 ms 47960 KB Output is correct
20 Correct 11 ms 47708 KB Output is correct
21 Correct 11 ms 47704 KB Output is correct
22 Correct 12 ms 47708 KB Output is correct
23 Correct 11 ms 47708 KB Output is correct
24 Correct 11 ms 47708 KB Output is correct
25 Correct 11 ms 47780 KB Output is correct
26 Correct 11 ms 47708 KB Output is correct
27 Correct 11 ms 47704 KB Output is correct
28 Correct 12 ms 47708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47700 KB Output is correct
2 Correct 13 ms 47704 KB Output is correct
3 Correct 12 ms 47704 KB Output is correct
4 Correct 12 ms 47708 KB Output is correct
5 Correct 11 ms 47708 KB Output is correct
6 Correct 11 ms 47708 KB Output is correct
7 Correct 12 ms 47808 KB Output is correct
8 Correct 12 ms 47704 KB Output is correct
9 Correct 12 ms 47704 KB Output is correct
10 Correct 11 ms 47708 KB Output is correct
11 Correct 11 ms 47708 KB Output is correct
12 Correct 11 ms 47708 KB Output is correct
13 Correct 10 ms 47708 KB Output is correct
14 Correct 11 ms 47708 KB Output is correct
15 Correct 11 ms 47780 KB Output is correct
16 Correct 12 ms 47764 KB Output is correct
17 Correct 10 ms 47704 KB Output is correct
18 Correct 11 ms 47708 KB Output is correct
19 Correct 11 ms 47960 KB Output is correct
20 Correct 11 ms 47708 KB Output is correct
21 Correct 11 ms 47704 KB Output is correct
22 Correct 12 ms 47708 KB Output is correct
23 Correct 11 ms 47708 KB Output is correct
24 Correct 11 ms 47708 KB Output is correct
25 Correct 11 ms 47780 KB Output is correct
26 Correct 11 ms 47708 KB Output is correct
27 Correct 11 ms 47704 KB Output is correct
28 Correct 12 ms 47708 KB Output is correct
29 Correct 11 ms 47712 KB Output is correct
30 Correct 13 ms 47708 KB Output is correct
31 Correct 11 ms 47708 KB Output is correct
32 Correct 11 ms 47740 KB Output is correct
33 Correct 11 ms 47808 KB Output is correct
34 Correct 11 ms 47704 KB Output is correct
35 Correct 12 ms 47704 KB Output is correct
36 Correct 11 ms 47708 KB Output is correct
37 Correct 11 ms 47812 KB Output is correct
38 Correct 12 ms 47708 KB Output is correct
39 Correct 12 ms 47704 KB Output is correct
40 Correct 11 ms 47708 KB Output is correct
41 Correct 11 ms 47776 KB Output is correct
42 Correct 11 ms 47708 KB Output is correct
43 Correct 11 ms 47708 KB Output is correct
44 Correct 11 ms 47784 KB Output is correct
45 Correct 11 ms 47756 KB Output is correct
46 Correct 11 ms 47708 KB Output is correct
47 Correct 10 ms 47708 KB Output is correct
48 Correct 11 ms 47708 KB Output is correct
49 Correct 11 ms 47708 KB Output is correct
50 Correct 13 ms 47744 KB Output is correct
51 Correct 11 ms 47708 KB Output is correct
52 Correct 11 ms 47708 KB Output is correct
53 Correct 10 ms 47708 KB Output is correct
54 Correct 12 ms 47720 KB Output is correct
55 Correct 11 ms 47708 KB Output is correct
56 Correct 11 ms 47708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 268 ms 155548 KB Output is correct
2 Correct 276 ms 162224 KB Output is correct
3 Correct 252 ms 162924 KB Output is correct
4 Correct 253 ms 162224 KB Output is correct
5 Correct 245 ms 163016 KB Output is correct
6 Correct 290 ms 162736 KB Output is correct
7 Correct 248 ms 162228 KB Output is correct
8 Correct 252 ms 162484 KB Output is correct
9 Correct 239 ms 162368 KB Output is correct
10 Correct 247 ms 162128 KB Output is correct
11 Correct 247 ms 162284 KB Output is correct
12 Correct 242 ms 162240 KB Output is correct
13 Correct 11 ms 47720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47700 KB Output is correct
2 Correct 13 ms 47704 KB Output is correct
3 Correct 12 ms 47704 KB Output is correct
4 Correct 12 ms 47708 KB Output is correct
5 Correct 11 ms 47708 KB Output is correct
6 Correct 11 ms 47708 KB Output is correct
7 Correct 12 ms 47808 KB Output is correct
8 Correct 12 ms 47704 KB Output is correct
9 Correct 12 ms 47704 KB Output is correct
10 Correct 11 ms 47708 KB Output is correct
11 Correct 11 ms 47708 KB Output is correct
12 Correct 11 ms 47708 KB Output is correct
13 Correct 10 ms 47708 KB Output is correct
14 Correct 11 ms 47708 KB Output is correct
15 Correct 11 ms 47780 KB Output is correct
16 Correct 12 ms 47764 KB Output is correct
17 Correct 10 ms 47704 KB Output is correct
18 Correct 11 ms 47708 KB Output is correct
19 Correct 11 ms 47960 KB Output is correct
20 Correct 11 ms 47708 KB Output is correct
21 Correct 11 ms 47704 KB Output is correct
22 Correct 12 ms 47708 KB Output is correct
23 Correct 11 ms 47708 KB Output is correct
24 Correct 11 ms 47708 KB Output is correct
25 Correct 11 ms 47780 KB Output is correct
26 Correct 11 ms 47708 KB Output is correct
27 Correct 11 ms 47704 KB Output is correct
28 Correct 12 ms 47708 KB Output is correct
29 Correct 11 ms 47712 KB Output is correct
30 Correct 13 ms 47708 KB Output is correct
31 Correct 11 ms 47708 KB Output is correct
32 Correct 11 ms 47740 KB Output is correct
33 Correct 11 ms 47808 KB Output is correct
34 Correct 11 ms 47704 KB Output is correct
35 Correct 12 ms 47704 KB Output is correct
36 Correct 11 ms 47708 KB Output is correct
37 Correct 11 ms 47812 KB Output is correct
38 Correct 12 ms 47708 KB Output is correct
39 Correct 12 ms 47704 KB Output is correct
40 Correct 11 ms 47708 KB Output is correct
41 Correct 11 ms 47776 KB Output is correct
42 Correct 11 ms 47708 KB Output is correct
43 Correct 11 ms 47708 KB Output is correct
44 Correct 11 ms 47784 KB Output is correct
45 Correct 11 ms 47756 KB Output is correct
46 Correct 11 ms 47708 KB Output is correct
47 Correct 10 ms 47708 KB Output is correct
48 Correct 11 ms 47708 KB Output is correct
49 Correct 11 ms 47708 KB Output is correct
50 Correct 13 ms 47744 KB Output is correct
51 Correct 11 ms 47708 KB Output is correct
52 Correct 11 ms 47708 KB Output is correct
53 Correct 10 ms 47708 KB Output is correct
54 Correct 12 ms 47720 KB Output is correct
55 Correct 11 ms 47708 KB Output is correct
56 Correct 11 ms 47708 KB Output is correct
57 Correct 11 ms 47708 KB Output is correct
58 Correct 13 ms 47704 KB Output is correct
59 Correct 11 ms 48004 KB Output is correct
60 Correct 11 ms 47768 KB Output is correct
61 Correct 11 ms 47748 KB Output is correct
62 Correct 11 ms 47812 KB Output is correct
63 Correct 11 ms 47708 KB Output is correct
64 Correct 11 ms 47716 KB Output is correct
65 Correct 11 ms 47704 KB Output is correct
66 Correct 11 ms 47708 KB Output is correct
67 Correct 11 ms 47708 KB Output is correct
68 Correct 11 ms 47708 KB Output is correct
69 Correct 11 ms 47708 KB Output is correct
70 Correct 11 ms 47752 KB Output is correct
71 Correct 11 ms 47704 KB Output is correct
72 Correct 11 ms 47708 KB Output is correct
73 Correct 11 ms 47708 KB Output is correct
74 Correct 11 ms 47708 KB Output is correct
75 Correct 12 ms 47708 KB Output is correct
76 Correct 11 ms 47708 KB Output is correct
77 Correct 11 ms 47708 KB Output is correct
78 Correct 11 ms 47708 KB Output is correct
79 Correct 12 ms 47708 KB Output is correct
80 Correct 11 ms 47708 KB Output is correct
81 Correct 12 ms 47736 KB Output is correct
82 Correct 11 ms 47704 KB Output is correct
83 Correct 11 ms 47712 KB Output is correct
84 Correct 11 ms 47708 KB Output is correct
85 Correct 11 ms 47708 KB Output is correct
86 Correct 11 ms 47708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47700 KB Output is correct
2 Correct 13 ms 47704 KB Output is correct
3 Correct 12 ms 47704 KB Output is correct
4 Correct 12 ms 47708 KB Output is correct
5 Correct 11 ms 47708 KB Output is correct
6 Correct 11 ms 47708 KB Output is correct
7 Correct 12 ms 47808 KB Output is correct
8 Correct 12 ms 47704 KB Output is correct
9 Correct 12 ms 47704 KB Output is correct
10 Correct 11 ms 47708 KB Output is correct
11 Correct 11 ms 47708 KB Output is correct
12 Correct 11 ms 47708 KB Output is correct
13 Correct 10 ms 47708 KB Output is correct
14 Correct 11 ms 47708 KB Output is correct
15 Correct 11 ms 47780 KB Output is correct
16 Correct 12 ms 47764 KB Output is correct
17 Correct 10 ms 47704 KB Output is correct
18 Correct 11 ms 47708 KB Output is correct
19 Correct 11 ms 47960 KB Output is correct
20 Correct 11 ms 47708 KB Output is correct
21 Correct 11 ms 47704 KB Output is correct
22 Correct 12 ms 47708 KB Output is correct
23 Correct 11 ms 47708 KB Output is correct
24 Correct 11 ms 47708 KB Output is correct
25 Correct 11 ms 47780 KB Output is correct
26 Correct 11 ms 47708 KB Output is correct
27 Correct 11 ms 47704 KB Output is correct
28 Correct 12 ms 47708 KB Output is correct
29 Correct 11 ms 47712 KB Output is correct
30 Correct 13 ms 47708 KB Output is correct
31 Correct 11 ms 47708 KB Output is correct
32 Correct 11 ms 47740 KB Output is correct
33 Correct 11 ms 47808 KB Output is correct
34 Correct 11 ms 47704 KB Output is correct
35 Correct 12 ms 47704 KB Output is correct
36 Correct 11 ms 47708 KB Output is correct
37 Correct 11 ms 47812 KB Output is correct
38 Correct 12 ms 47708 KB Output is correct
39 Correct 12 ms 47704 KB Output is correct
40 Correct 11 ms 47708 KB Output is correct
41 Correct 11 ms 47776 KB Output is correct
42 Correct 11 ms 47708 KB Output is correct
43 Correct 11 ms 47708 KB Output is correct
44 Correct 11 ms 47784 KB Output is correct
45 Correct 11 ms 47756 KB Output is correct
46 Correct 11 ms 47708 KB Output is correct
47 Correct 10 ms 47708 KB Output is correct
48 Correct 11 ms 47708 KB Output is correct
49 Correct 11 ms 47708 KB Output is correct
50 Correct 13 ms 47744 KB Output is correct
51 Correct 11 ms 47708 KB Output is correct
52 Correct 11 ms 47708 KB Output is correct
53 Correct 10 ms 47708 KB Output is correct
54 Correct 12 ms 47720 KB Output is correct
55 Correct 11 ms 47708 KB Output is correct
56 Correct 11 ms 47708 KB Output is correct
57 Correct 268 ms 155548 KB Output is correct
58 Correct 276 ms 162224 KB Output is correct
59 Correct 252 ms 162924 KB Output is correct
60 Correct 253 ms 162224 KB Output is correct
61 Correct 245 ms 163016 KB Output is correct
62 Correct 290 ms 162736 KB Output is correct
63 Correct 248 ms 162228 KB Output is correct
64 Correct 252 ms 162484 KB Output is correct
65 Correct 239 ms 162368 KB Output is correct
66 Correct 247 ms 162128 KB Output is correct
67 Correct 247 ms 162284 KB Output is correct
68 Correct 242 ms 162240 KB Output is correct
69 Correct 11 ms 47720 KB Output is correct
70 Correct 11 ms 47708 KB Output is correct
71 Correct 13 ms 47704 KB Output is correct
72 Correct 11 ms 48004 KB Output is correct
73 Correct 11 ms 47768 KB Output is correct
74 Correct 11 ms 47748 KB Output is correct
75 Correct 11 ms 47812 KB Output is correct
76 Correct 11 ms 47708 KB Output is correct
77 Correct 11 ms 47716 KB Output is correct
78 Correct 11 ms 47704 KB Output is correct
79 Correct 11 ms 47708 KB Output is correct
80 Correct 11 ms 47708 KB Output is correct
81 Correct 11 ms 47708 KB Output is correct
82 Correct 11 ms 47708 KB Output is correct
83 Correct 11 ms 47752 KB Output is correct
84 Correct 11 ms 47704 KB Output is correct
85 Correct 11 ms 47708 KB Output is correct
86 Correct 11 ms 47708 KB Output is correct
87 Correct 11 ms 47708 KB Output is correct
88 Correct 12 ms 47708 KB Output is correct
89 Correct 11 ms 47708 KB Output is correct
90 Correct 11 ms 47708 KB Output is correct
91 Correct 11 ms 47708 KB Output is correct
92 Correct 12 ms 47708 KB Output is correct
93 Correct 11 ms 47708 KB Output is correct
94 Correct 12 ms 47736 KB Output is correct
95 Correct 11 ms 47704 KB Output is correct
96 Correct 11 ms 47712 KB Output is correct
97 Correct 11 ms 47708 KB Output is correct
98 Correct 11 ms 47708 KB Output is correct
99 Correct 11 ms 47708 KB Output is correct
100 Correct 215 ms 115684 KB Output is correct
101 Correct 220 ms 115740 KB Output is correct
102 Correct 208 ms 115812 KB Output is correct
103 Correct 210 ms 115888 KB Output is correct
104 Correct 214 ms 115636 KB Output is correct
105 Correct 241 ms 133556 KB Output is correct
106 Correct 236 ms 132788 KB Output is correct
107 Correct 228 ms 132656 KB Output is correct
108 Correct 237 ms 133136 KB Output is correct
109 Correct 240 ms 133732 KB Output is correct
110 Correct 219 ms 115772 KB Output is correct
111 Correct 243 ms 116160 KB Output is correct
112 Correct 212 ms 115896 KB Output is correct
113 Correct 251 ms 115644 KB Output is correct
114 Correct 213 ms 116180 KB Output is correct
115 Correct 258 ms 162420 KB Output is correct
116 Correct 252 ms 162996 KB Output is correct
117 Correct 306 ms 162164 KB Output is correct
118 Correct 237 ms 162360 KB Output is correct
119 Correct 246 ms 162224 KB Output is correct
120 Correct 210 ms 108092 KB Output is correct
121 Correct 227 ms 115696 KB Output is correct
122 Correct 226 ms 115780 KB Output is correct
123 Correct 222 ms 115856 KB Output is correct
124 Correct 217 ms 141228 KB Output is correct
125 Correct 218 ms 138696 KB Output is correct
126 Correct 220 ms 141844 KB Output is correct
127 Correct 216 ms 138676 KB Output is correct
128 Correct 111 ms 84452 KB Output is correct
129 Correct 109 ms 84488 KB Output is correct
130 Correct 121 ms 84436 KB Output is correct
131 Correct 11 ms 47704 KB Output is correct