#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6 + 12, MOD = 998244353;
string s;
int m, n, col, val[N], l[N], r[N];
vector<int> st, g[N];
bool ok[N];
void dfs(int v) {
if(v <= col) {
l[v] = 1, r[v] = col;
return;
}
for(int to:g[v]) {
dfs(to);
}
if(ok[v]) {
r[v] = max(r[g[v][0]], r[g[v][1]]);
l[v] = l[g[v][0]] + l[g[v][1]];
} else {
l[v] = min(l[g[v][0]], l[g[v][1]]);
r[v] = col - ((col - r[g[v][0]] + 1) + (col - r[g[v][1]] + 1)) + 1;
}
}
void test() {
cin >> s;
m = (int)s.size();
for(int i = 0; i < m; i++) {
if(s[i] == '?') {
col++;
}
}
n = col;
for(int i = 0; i < m; i++) {
if(s[i] == '(') {
if(!st.empty()) {
g[st.back()].push_back(n + 1);
}
st.push_back(++n);
if(s[i - 1] == 'x') {
ok[n] = 1;
}
} else if(s[i] == ')') {
st.pop_back();
}
}
int it = 0;
for(int i = col + 1; i <= n; i++) {
int f = (int)g[i].size();
for(int j = 0; j < 2 - f; j++) {
g[i].push_back(++it);
}
}
dfs(col + 1);
cout << r[col + 1] - l[col + 1] + 1 << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47388 KB |
Output is correct |
4 |
Correct |
19 ms |
47196 KB |
Output is correct |
5 |
Correct |
20 ms |
47452 KB |
Output is correct |
6 |
Correct |
19 ms |
47452 KB |
Output is correct |
7 |
Correct |
19 ms |
47452 KB |
Output is correct |
8 |
Correct |
20 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47448 KB |
Output is correct |
10 |
Correct |
19 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
22 ms |
47192 KB |
Output is correct |
13 |
Correct |
18 ms |
47452 KB |
Output is correct |
14 |
Correct |
19 ms |
47364 KB |
Output is correct |
15 |
Correct |
19 ms |
47452 KB |
Output is correct |
16 |
Correct |
19 ms |
47192 KB |
Output is correct |
17 |
Correct |
18 ms |
47448 KB |
Output is correct |
18 |
Correct |
20 ms |
47420 KB |
Output is correct |
19 |
Correct |
18 ms |
47452 KB |
Output is correct |
20 |
Correct |
18 ms |
47308 KB |
Output is correct |
21 |
Correct |
19 ms |
47448 KB |
Output is correct |
22 |
Correct |
19 ms |
47196 KB |
Output is correct |
23 |
Correct |
19 ms |
47192 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
18 ms |
47244 KB |
Output is correct |
26 |
Correct |
19 ms |
47448 KB |
Output is correct |
27 |
Correct |
18 ms |
47452 KB |
Output is correct |
28 |
Correct |
20 ms |
47452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47388 KB |
Output is correct |
4 |
Correct |
19 ms |
47196 KB |
Output is correct |
5 |
Correct |
20 ms |
47452 KB |
Output is correct |
6 |
Correct |
19 ms |
47452 KB |
Output is correct |
7 |
Correct |
19 ms |
47452 KB |
Output is correct |
8 |
Correct |
20 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47448 KB |
Output is correct |
10 |
Correct |
19 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
22 ms |
47192 KB |
Output is correct |
13 |
Correct |
18 ms |
47452 KB |
Output is correct |
14 |
Correct |
19 ms |
47364 KB |
Output is correct |
15 |
Correct |
19 ms |
47452 KB |
Output is correct |
16 |
Correct |
19 ms |
47192 KB |
Output is correct |
17 |
Correct |
18 ms |
47448 KB |
Output is correct |
18 |
Correct |
20 ms |
47420 KB |
Output is correct |
19 |
Correct |
18 ms |
47452 KB |
Output is correct |
20 |
Correct |
18 ms |
47308 KB |
Output is correct |
21 |
Correct |
19 ms |
47448 KB |
Output is correct |
22 |
Correct |
19 ms |
47196 KB |
Output is correct |
23 |
Correct |
19 ms |
47192 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
18 ms |
47244 KB |
Output is correct |
26 |
Correct |
19 ms |
47448 KB |
Output is correct |
27 |
Correct |
18 ms |
47452 KB |
Output is correct |
28 |
Correct |
20 ms |
47452 KB |
Output is correct |
29 |
Correct |
19 ms |
47452 KB |
Output is correct |
30 |
Correct |
19 ms |
47196 KB |
Output is correct |
31 |
Correct |
19 ms |
47448 KB |
Output is correct |
32 |
Correct |
19 ms |
47448 KB |
Output is correct |
33 |
Correct |
20 ms |
47448 KB |
Output is correct |
34 |
Correct |
19 ms |
47448 KB |
Output is correct |
35 |
Correct |
19 ms |
47192 KB |
Output is correct |
36 |
Correct |
19 ms |
47196 KB |
Output is correct |
37 |
Correct |
20 ms |
47448 KB |
Output is correct |
38 |
Correct |
20 ms |
47448 KB |
Output is correct |
39 |
Correct |
19 ms |
47452 KB |
Output is correct |
40 |
Correct |
22 ms |
47240 KB |
Output is correct |
41 |
Correct |
19 ms |
47368 KB |
Output is correct |
42 |
Correct |
19 ms |
47452 KB |
Output is correct |
43 |
Correct |
18 ms |
47352 KB |
Output is correct |
44 |
Correct |
18 ms |
47452 KB |
Output is correct |
45 |
Correct |
20 ms |
47192 KB |
Output is correct |
46 |
Correct |
20 ms |
47192 KB |
Output is correct |
47 |
Correct |
20 ms |
47452 KB |
Output is correct |
48 |
Correct |
20 ms |
47196 KB |
Output is correct |
49 |
Correct |
20 ms |
47448 KB |
Output is correct |
50 |
Correct |
20 ms |
47364 KB |
Output is correct |
51 |
Correct |
19 ms |
47196 KB |
Output is correct |
52 |
Correct |
20 ms |
47448 KB |
Output is correct |
53 |
Correct |
18 ms |
47196 KB |
Output is correct |
54 |
Correct |
19 ms |
47416 KB |
Output is correct |
55 |
Correct |
21 ms |
47448 KB |
Output is correct |
56 |
Correct |
20 ms |
47452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
174540 KB |
Output is correct |
2 |
Correct |
178 ms |
175544 KB |
Output is correct |
3 |
Correct |
181 ms |
175560 KB |
Output is correct |
4 |
Correct |
179 ms |
175540 KB |
Output is correct |
5 |
Correct |
179 ms |
175496 KB |
Output is correct |
6 |
Correct |
173 ms |
175564 KB |
Output is correct |
7 |
Correct |
175 ms |
175376 KB |
Output is correct |
8 |
Correct |
181 ms |
175556 KB |
Output is correct |
9 |
Correct |
176 ms |
175564 KB |
Output is correct |
10 |
Correct |
172 ms |
175424 KB |
Output is correct |
11 |
Correct |
172 ms |
175552 KB |
Output is correct |
12 |
Correct |
166 ms |
175544 KB |
Output is correct |
13 |
Correct |
18 ms |
47448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47388 KB |
Output is correct |
4 |
Correct |
19 ms |
47196 KB |
Output is correct |
5 |
Correct |
20 ms |
47452 KB |
Output is correct |
6 |
Correct |
19 ms |
47452 KB |
Output is correct |
7 |
Correct |
19 ms |
47452 KB |
Output is correct |
8 |
Correct |
20 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47448 KB |
Output is correct |
10 |
Correct |
19 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
22 ms |
47192 KB |
Output is correct |
13 |
Correct |
18 ms |
47452 KB |
Output is correct |
14 |
Correct |
19 ms |
47364 KB |
Output is correct |
15 |
Correct |
19 ms |
47452 KB |
Output is correct |
16 |
Correct |
19 ms |
47192 KB |
Output is correct |
17 |
Correct |
18 ms |
47448 KB |
Output is correct |
18 |
Correct |
20 ms |
47420 KB |
Output is correct |
19 |
Correct |
18 ms |
47452 KB |
Output is correct |
20 |
Correct |
18 ms |
47308 KB |
Output is correct |
21 |
Correct |
19 ms |
47448 KB |
Output is correct |
22 |
Correct |
19 ms |
47196 KB |
Output is correct |
23 |
Correct |
19 ms |
47192 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
18 ms |
47244 KB |
Output is correct |
26 |
Correct |
19 ms |
47448 KB |
Output is correct |
27 |
Correct |
18 ms |
47452 KB |
Output is correct |
28 |
Correct |
20 ms |
47452 KB |
Output is correct |
29 |
Correct |
19 ms |
47452 KB |
Output is correct |
30 |
Correct |
19 ms |
47196 KB |
Output is correct |
31 |
Correct |
19 ms |
47448 KB |
Output is correct |
32 |
Correct |
19 ms |
47448 KB |
Output is correct |
33 |
Correct |
20 ms |
47448 KB |
Output is correct |
34 |
Correct |
19 ms |
47448 KB |
Output is correct |
35 |
Correct |
19 ms |
47192 KB |
Output is correct |
36 |
Correct |
19 ms |
47196 KB |
Output is correct |
37 |
Correct |
20 ms |
47448 KB |
Output is correct |
38 |
Correct |
20 ms |
47448 KB |
Output is correct |
39 |
Correct |
19 ms |
47452 KB |
Output is correct |
40 |
Correct |
22 ms |
47240 KB |
Output is correct |
41 |
Correct |
19 ms |
47368 KB |
Output is correct |
42 |
Correct |
19 ms |
47452 KB |
Output is correct |
43 |
Correct |
18 ms |
47352 KB |
Output is correct |
44 |
Correct |
18 ms |
47452 KB |
Output is correct |
45 |
Correct |
20 ms |
47192 KB |
Output is correct |
46 |
Correct |
20 ms |
47192 KB |
Output is correct |
47 |
Correct |
20 ms |
47452 KB |
Output is correct |
48 |
Correct |
20 ms |
47196 KB |
Output is correct |
49 |
Correct |
20 ms |
47448 KB |
Output is correct |
50 |
Correct |
20 ms |
47364 KB |
Output is correct |
51 |
Correct |
19 ms |
47196 KB |
Output is correct |
52 |
Correct |
20 ms |
47448 KB |
Output is correct |
53 |
Correct |
18 ms |
47196 KB |
Output is correct |
54 |
Correct |
19 ms |
47416 KB |
Output is correct |
55 |
Correct |
21 ms |
47448 KB |
Output is correct |
56 |
Correct |
20 ms |
47452 KB |
Output is correct |
57 |
Correct |
18 ms |
47448 KB |
Output is correct |
58 |
Correct |
18 ms |
47380 KB |
Output is correct |
59 |
Correct |
18 ms |
47452 KB |
Output is correct |
60 |
Correct |
18 ms |
47516 KB |
Output is correct |
61 |
Correct |
18 ms |
47448 KB |
Output is correct |
62 |
Correct |
20 ms |
47476 KB |
Output is correct |
63 |
Correct |
19 ms |
47452 KB |
Output is correct |
64 |
Correct |
18 ms |
47452 KB |
Output is correct |
65 |
Correct |
17 ms |
47452 KB |
Output is correct |
66 |
Correct |
18 ms |
47448 KB |
Output is correct |
67 |
Correct |
20 ms |
47452 KB |
Output is correct |
68 |
Correct |
20 ms |
47336 KB |
Output is correct |
69 |
Correct |
18 ms |
47448 KB |
Output is correct |
70 |
Correct |
20 ms |
47452 KB |
Output is correct |
71 |
Correct |
20 ms |
47444 KB |
Output is correct |
72 |
Correct |
19 ms |
47452 KB |
Output is correct |
73 |
Correct |
19 ms |
47452 KB |
Output is correct |
74 |
Correct |
19 ms |
47448 KB |
Output is correct |
75 |
Correct |
19 ms |
47452 KB |
Output is correct |
76 |
Correct |
19 ms |
47548 KB |
Output is correct |
77 |
Correct |
19 ms |
47452 KB |
Output is correct |
78 |
Correct |
19 ms |
47376 KB |
Output is correct |
79 |
Correct |
19 ms |
47448 KB |
Output is correct |
80 |
Correct |
21 ms |
47424 KB |
Output is correct |
81 |
Correct |
19 ms |
47452 KB |
Output is correct |
82 |
Correct |
18 ms |
47452 KB |
Output is correct |
83 |
Correct |
19 ms |
47284 KB |
Output is correct |
84 |
Correct |
20 ms |
47448 KB |
Output is correct |
85 |
Correct |
19 ms |
47448 KB |
Output is correct |
86 |
Correct |
18 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47452 KB |
Output is correct |
3 |
Correct |
19 ms |
47388 KB |
Output is correct |
4 |
Correct |
19 ms |
47196 KB |
Output is correct |
5 |
Correct |
20 ms |
47452 KB |
Output is correct |
6 |
Correct |
19 ms |
47452 KB |
Output is correct |
7 |
Correct |
19 ms |
47452 KB |
Output is correct |
8 |
Correct |
20 ms |
47452 KB |
Output is correct |
9 |
Correct |
21 ms |
47448 KB |
Output is correct |
10 |
Correct |
19 ms |
47448 KB |
Output is correct |
11 |
Correct |
19 ms |
47452 KB |
Output is correct |
12 |
Correct |
22 ms |
47192 KB |
Output is correct |
13 |
Correct |
18 ms |
47452 KB |
Output is correct |
14 |
Correct |
19 ms |
47364 KB |
Output is correct |
15 |
Correct |
19 ms |
47452 KB |
Output is correct |
16 |
Correct |
19 ms |
47192 KB |
Output is correct |
17 |
Correct |
18 ms |
47448 KB |
Output is correct |
18 |
Correct |
20 ms |
47420 KB |
Output is correct |
19 |
Correct |
18 ms |
47452 KB |
Output is correct |
20 |
Correct |
18 ms |
47308 KB |
Output is correct |
21 |
Correct |
19 ms |
47448 KB |
Output is correct |
22 |
Correct |
19 ms |
47196 KB |
Output is correct |
23 |
Correct |
19 ms |
47192 KB |
Output is correct |
24 |
Correct |
20 ms |
47452 KB |
Output is correct |
25 |
Correct |
18 ms |
47244 KB |
Output is correct |
26 |
Correct |
19 ms |
47448 KB |
Output is correct |
27 |
Correct |
18 ms |
47452 KB |
Output is correct |
28 |
Correct |
20 ms |
47452 KB |
Output is correct |
29 |
Correct |
19 ms |
47452 KB |
Output is correct |
30 |
Correct |
19 ms |
47196 KB |
Output is correct |
31 |
Correct |
19 ms |
47448 KB |
Output is correct |
32 |
Correct |
19 ms |
47448 KB |
Output is correct |
33 |
Correct |
20 ms |
47448 KB |
Output is correct |
34 |
Correct |
19 ms |
47448 KB |
Output is correct |
35 |
Correct |
19 ms |
47192 KB |
Output is correct |
36 |
Correct |
19 ms |
47196 KB |
Output is correct |
37 |
Correct |
20 ms |
47448 KB |
Output is correct |
38 |
Correct |
20 ms |
47448 KB |
Output is correct |
39 |
Correct |
19 ms |
47452 KB |
Output is correct |
40 |
Correct |
22 ms |
47240 KB |
Output is correct |
41 |
Correct |
19 ms |
47368 KB |
Output is correct |
42 |
Correct |
19 ms |
47452 KB |
Output is correct |
43 |
Correct |
18 ms |
47352 KB |
Output is correct |
44 |
Correct |
18 ms |
47452 KB |
Output is correct |
45 |
Correct |
20 ms |
47192 KB |
Output is correct |
46 |
Correct |
20 ms |
47192 KB |
Output is correct |
47 |
Correct |
20 ms |
47452 KB |
Output is correct |
48 |
Correct |
20 ms |
47196 KB |
Output is correct |
49 |
Correct |
20 ms |
47448 KB |
Output is correct |
50 |
Correct |
20 ms |
47364 KB |
Output is correct |
51 |
Correct |
19 ms |
47196 KB |
Output is correct |
52 |
Correct |
20 ms |
47448 KB |
Output is correct |
53 |
Correct |
18 ms |
47196 KB |
Output is correct |
54 |
Correct |
19 ms |
47416 KB |
Output is correct |
55 |
Correct |
21 ms |
47448 KB |
Output is correct |
56 |
Correct |
20 ms |
47452 KB |
Output is correct |
57 |
Correct |
182 ms |
174540 KB |
Output is correct |
58 |
Correct |
178 ms |
175544 KB |
Output is correct |
59 |
Correct |
181 ms |
175560 KB |
Output is correct |
60 |
Correct |
179 ms |
175540 KB |
Output is correct |
61 |
Correct |
179 ms |
175496 KB |
Output is correct |
62 |
Correct |
173 ms |
175564 KB |
Output is correct |
63 |
Correct |
175 ms |
175376 KB |
Output is correct |
64 |
Correct |
181 ms |
175556 KB |
Output is correct |
65 |
Correct |
176 ms |
175564 KB |
Output is correct |
66 |
Correct |
172 ms |
175424 KB |
Output is correct |
67 |
Correct |
172 ms |
175552 KB |
Output is correct |
68 |
Correct |
166 ms |
175544 KB |
Output is correct |
69 |
Correct |
18 ms |
47448 KB |
Output is correct |
70 |
Correct |
18 ms |
47448 KB |
Output is correct |
71 |
Correct |
18 ms |
47380 KB |
Output is correct |
72 |
Correct |
18 ms |
47452 KB |
Output is correct |
73 |
Correct |
18 ms |
47516 KB |
Output is correct |
74 |
Correct |
18 ms |
47448 KB |
Output is correct |
75 |
Correct |
20 ms |
47476 KB |
Output is correct |
76 |
Correct |
19 ms |
47452 KB |
Output is correct |
77 |
Correct |
18 ms |
47452 KB |
Output is correct |
78 |
Correct |
17 ms |
47452 KB |
Output is correct |
79 |
Correct |
18 ms |
47448 KB |
Output is correct |
80 |
Correct |
20 ms |
47452 KB |
Output is correct |
81 |
Correct |
20 ms |
47336 KB |
Output is correct |
82 |
Correct |
18 ms |
47448 KB |
Output is correct |
83 |
Correct |
20 ms |
47452 KB |
Output is correct |
84 |
Correct |
20 ms |
47444 KB |
Output is correct |
85 |
Correct |
19 ms |
47452 KB |
Output is correct |
86 |
Correct |
19 ms |
47452 KB |
Output is correct |
87 |
Correct |
19 ms |
47448 KB |
Output is correct |
88 |
Correct |
19 ms |
47452 KB |
Output is correct |
89 |
Correct |
19 ms |
47548 KB |
Output is correct |
90 |
Correct |
19 ms |
47452 KB |
Output is correct |
91 |
Correct |
19 ms |
47376 KB |
Output is correct |
92 |
Correct |
19 ms |
47448 KB |
Output is correct |
93 |
Correct |
21 ms |
47424 KB |
Output is correct |
94 |
Correct |
19 ms |
47452 KB |
Output is correct |
95 |
Correct |
18 ms |
47452 KB |
Output is correct |
96 |
Correct |
19 ms |
47284 KB |
Output is correct |
97 |
Correct |
20 ms |
47448 KB |
Output is correct |
98 |
Correct |
19 ms |
47448 KB |
Output is correct |
99 |
Correct |
18 ms |
47352 KB |
Output is correct |
100 |
Correct |
138 ms |
109000 KB |
Output is correct |
101 |
Correct |
140 ms |
108960 KB |
Output is correct |
102 |
Correct |
143 ms |
108840 KB |
Output is correct |
103 |
Correct |
136 ms |
108988 KB |
Output is correct |
104 |
Correct |
127 ms |
109004 KB |
Output is correct |
105 |
Correct |
172 ms |
131016 KB |
Output is correct |
106 |
Correct |
174 ms |
131272 KB |
Output is correct |
107 |
Correct |
166 ms |
131264 KB |
Output is correct |
108 |
Correct |
172 ms |
131016 KB |
Output is correct |
109 |
Correct |
168 ms |
131016 KB |
Output is correct |
110 |
Correct |
151 ms |
109000 KB |
Output is correct |
111 |
Correct |
161 ms |
109008 KB |
Output is correct |
112 |
Correct |
145 ms |
109000 KB |
Output is correct |
113 |
Correct |
140 ms |
108968 KB |
Output is correct |
114 |
Correct |
144 ms |
109000 KB |
Output is correct |
115 |
Correct |
183 ms |
175564 KB |
Output is correct |
116 |
Correct |
186 ms |
175528 KB |
Output is correct |
117 |
Correct |
172 ms |
175556 KB |
Output is correct |
118 |
Correct |
190 ms |
175436 KB |
Output is correct |
119 |
Correct |
181 ms |
175520 KB |
Output is correct |
120 |
Correct |
151 ms |
107892 KB |
Output is correct |
121 |
Correct |
138 ms |
109012 KB |
Output is correct |
122 |
Correct |
153 ms |
109032 KB |
Output is correct |
123 |
Correct |
146 ms |
108996 KB |
Output is correct |
124 |
Correct |
159 ms |
142164 KB |
Output is correct |
125 |
Correct |
164 ms |
141728 KB |
Output is correct |
126 |
Correct |
163 ms |
142276 KB |
Output is correct |
127 |
Correct |
157 ms |
141768 KB |
Output is correct |
128 |
Correct |
73 ms |
79572 KB |
Output is correct |
129 |
Correct |
68 ms |
79568 KB |
Output is correct |
130 |
Correct |
66 ms |
79604 KB |
Output is correct |
131 |
Correct |
17 ms |
47192 KB |
Output is correct |