// In the name of God
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int N = 1e6 + 5;
string s;
bool f[N];
map<ll, int> M;
inline ll F(int l, int r) {
return l + 1LL * r * N;
}
pair<int, int> SOLVE(int L, int R) {
pair<int, int> ans;
//cout << L << ' ' << R << ' ' << v << endl;
if (L >= R)
return mp(1, 1);
int v = M[F(L, R)];
if (L == R - 1) {
return f[v] ? mp(2, 2) : mp(1, 1);
}
int mid = v;
pair<int, int> lt = SOLVE(L, mid - 1);
pair<int, int> rt = SOLVE(mid, R);
int n = R - L + 1, cl = mid - L, cr = R - mid + 1;
if (f[v]) {
ans.fi = lt.fi + rt.fi;
ans.se = n - min(cl - lt.se, cr - rt.se);
}
else {
ans.fi = min(lt.fi, rt.fi);
ans.se = lt.se + rt.se - 1;
}
return ans;
}
void solve() {
cin >> s;
vector<pair<pair<int, int>, bool> > st;
int cnt = 1;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') {
st.pb(mp(mp(cnt - 1, 0), s[i - 1] == 'x'));
}
else if (s[i] == ',') {
st.back().fi.se = cnt++;
}
else if (s[i] == ')') {
pair<pair<int, int>, bool> p = st.back();
st.pop_back();
M[F(p.fi.fi, cnt - 1)] = p.fi.se;
f[p.fi.se] = p.se;
}
}
pair<int, int> p = SOLVE(0, cnt - 1);
cout << p.se - p.fi + 1 << '\n';
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
324 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
324 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
328 KB |
Output is correct |
54 |
Correct |
0 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
166604 KB |
Output is correct |
2 |
Correct |
303 ms |
166656 KB |
Output is correct |
3 |
Correct |
295 ms |
166588 KB |
Output is correct |
4 |
Correct |
337 ms |
167524 KB |
Output is correct |
5 |
Correct |
303 ms |
167196 KB |
Output is correct |
6 |
Correct |
301 ms |
167560 KB |
Output is correct |
7 |
Correct |
305 ms |
167040 KB |
Output is correct |
8 |
Correct |
307 ms |
167220 KB |
Output is correct |
9 |
Correct |
300 ms |
166640 KB |
Output is correct |
10 |
Correct |
313 ms |
166528 KB |
Output is correct |
11 |
Correct |
321 ms |
167600 KB |
Output is correct |
12 |
Correct |
298 ms |
166728 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
324 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
324 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
328 KB |
Output is correct |
54 |
Correct |
0 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
328 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
328 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
336 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
460 KB |
Output is correct |
73 |
Correct |
1 ms |
468 KB |
Output is correct |
74 |
Correct |
1 ms |
460 KB |
Output is correct |
75 |
Correct |
1 ms |
468 KB |
Output is correct |
76 |
Correct |
1 ms |
456 KB |
Output is correct |
77 |
Correct |
1 ms |
340 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
1 ms |
340 KB |
Output is correct |
81 |
Correct |
1 ms |
340 KB |
Output is correct |
82 |
Correct |
1 ms |
324 KB |
Output is correct |
83 |
Correct |
1 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
1 ms |
340 KB |
Output is correct |
86 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
324 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
324 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
328 KB |
Output is correct |
54 |
Correct |
0 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
328 KB |
Output is correct |
57 |
Correct |
319 ms |
166604 KB |
Output is correct |
58 |
Correct |
303 ms |
166656 KB |
Output is correct |
59 |
Correct |
295 ms |
166588 KB |
Output is correct |
60 |
Correct |
337 ms |
167524 KB |
Output is correct |
61 |
Correct |
303 ms |
167196 KB |
Output is correct |
62 |
Correct |
301 ms |
167560 KB |
Output is correct |
63 |
Correct |
305 ms |
167040 KB |
Output is correct |
64 |
Correct |
307 ms |
167220 KB |
Output is correct |
65 |
Correct |
300 ms |
166640 KB |
Output is correct |
66 |
Correct |
313 ms |
166528 KB |
Output is correct |
67 |
Correct |
321 ms |
167600 KB |
Output is correct |
68 |
Correct |
298 ms |
166728 KB |
Output is correct |
69 |
Correct |
2 ms |
212 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
328 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
1 ms |
340 KB |
Output is correct |
76 |
Correct |
1 ms |
336 KB |
Output is correct |
77 |
Correct |
1 ms |
340 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
1 ms |
340 KB |
Output is correct |
81 |
Correct |
1 ms |
340 KB |
Output is correct |
82 |
Correct |
1 ms |
340 KB |
Output is correct |
83 |
Correct |
1 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
1 ms |
460 KB |
Output is correct |
86 |
Correct |
1 ms |
468 KB |
Output is correct |
87 |
Correct |
1 ms |
460 KB |
Output is correct |
88 |
Correct |
1 ms |
468 KB |
Output is correct |
89 |
Correct |
1 ms |
456 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
332 KB |
Output is correct |
92 |
Correct |
1 ms |
340 KB |
Output is correct |
93 |
Correct |
1 ms |
340 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
324 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
1 ms |
340 KB |
Output is correct |
98 |
Correct |
1 ms |
340 KB |
Output is correct |
99 |
Correct |
1 ms |
212 KB |
Output is correct |
100 |
Correct |
282 ms |
77424 KB |
Output is correct |
101 |
Correct |
277 ms |
76920 KB |
Output is correct |
102 |
Correct |
279 ms |
76904 KB |
Output is correct |
103 |
Correct |
283 ms |
76948 KB |
Output is correct |
104 |
Correct |
287 ms |
76512 KB |
Output is correct |
105 |
Correct |
289 ms |
106756 KB |
Output is correct |
106 |
Correct |
294 ms |
106488 KB |
Output is correct |
107 |
Correct |
282 ms |
106492 KB |
Output is correct |
108 |
Correct |
282 ms |
107044 KB |
Output is correct |
109 |
Correct |
284 ms |
107348 KB |
Output is correct |
110 |
Correct |
275 ms |
77460 KB |
Output is correct |
111 |
Correct |
267 ms |
76864 KB |
Output is correct |
112 |
Correct |
275 ms |
77224 KB |
Output is correct |
113 |
Correct |
266 ms |
76704 KB |
Output is correct |
114 |
Correct |
267 ms |
76968 KB |
Output is correct |
115 |
Correct |
312 ms |
167476 KB |
Output is correct |
116 |
Correct |
306 ms |
166932 KB |
Output is correct |
117 |
Correct |
307 ms |
167280 KB |
Output is correct |
118 |
Correct |
306 ms |
166832 KB |
Output is correct |
119 |
Correct |
310 ms |
166860 KB |
Output is correct |
120 |
Correct |
284 ms |
77296 KB |
Output is correct |
121 |
Correct |
284 ms |
77284 KB |
Output is correct |
122 |
Correct |
276 ms |
77000 KB |
Output is correct |
123 |
Correct |
279 ms |
77272 KB |
Output is correct |
124 |
Correct |
334 ms |
122416 KB |
Output is correct |
125 |
Correct |
352 ms |
122368 KB |
Output is correct |
126 |
Correct |
350 ms |
121932 KB |
Output is correct |
127 |
Correct |
352 ms |
122496 KB |
Output is correct |
128 |
Correct |
142 ms |
40680 KB |
Output is correct |
129 |
Correct |
134 ms |
40508 KB |
Output is correct |
130 |
Correct |
142 ms |
40680 KB |
Output is correct |
131 |
Correct |
1 ms |
212 KB |
Output is correct |