#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#include <stack>
#define ff first
#define ss second
using namespace std;
string s;
int n, comma[7000005];
void pre() {
stack<int> st;
for(int i = 0; i < s.size(); i++) {
if(s[i] == ')') {
if(s[i + 1] == ',') {
comma[st.top()] = i + 1;
st.pop();
}
}
if(s[i] == '(') {
if(s[i + 2] == ',') comma[i] = i + 2;
else st.push(i);
}
}
}
pair<int, int> solve(int l, int r) {
if(l == r) return {0, 0};
int cnt = 0, x = comma[l + 3];
pair<int, int> a = solve(4 + l, x - 1), b = solve(x + 1, r - 1);
if(s[1 + l] == 'i') return {a.ff + b.ff + 1, min(a.ss, b.ss)};
else return {min(a.ff, b.ff), a.ss + b.ss + 1};
return {0, 0};
}
int main() {
memset(comma, -1, sizeof(comma));
ios::sync_with_stdio(0);cin.tie(0);
cin >> s;
pre();
n = (int)s.size() / 7 + 1;
pair<int, int> ans = solve(0, (int)s.size() - 1);
cout << n - ans.ff - ans.ss;
}
Compilation message
Main.cpp: In function 'void pre()':
Main.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp: In function 'std::pair<int, int> solve(int, int)':
Main.cpp:45:6: warning: unused variable 'cnt' [-Wunused-variable]
45 | int cnt = 0, x = comma[l + 3];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
27604 KB |
Output is correct |
2 |
Correct |
11 ms |
27724 KB |
Output is correct |
3 |
Correct |
10 ms |
27724 KB |
Output is correct |
4 |
Correct |
11 ms |
27712 KB |
Output is correct |
5 |
Correct |
10 ms |
27636 KB |
Output is correct |
6 |
Correct |
11 ms |
27604 KB |
Output is correct |
7 |
Correct |
11 ms |
27604 KB |
Output is correct |
8 |
Correct |
10 ms |
27604 KB |
Output is correct |
9 |
Correct |
10 ms |
27604 KB |
Output is correct |
10 |
Correct |
10 ms |
27604 KB |
Output is correct |
11 |
Correct |
10 ms |
27604 KB |
Output is correct |
12 |
Correct |
10 ms |
27604 KB |
Output is correct |
13 |
Correct |
12 ms |
27604 KB |
Output is correct |
14 |
Correct |
11 ms |
27720 KB |
Output is correct |
15 |
Correct |
11 ms |
27604 KB |
Output is correct |
16 |
Correct |
11 ms |
27720 KB |
Output is correct |
17 |
Correct |
11 ms |
27636 KB |
Output is correct |
18 |
Correct |
11 ms |
27620 KB |
Output is correct |
19 |
Correct |
11 ms |
27716 KB |
Output is correct |
20 |
Correct |
11 ms |
27604 KB |
Output is correct |
21 |
Correct |
11 ms |
27644 KB |
Output is correct |
22 |
Correct |
11 ms |
27604 KB |
Output is correct |
23 |
Correct |
11 ms |
27604 KB |
Output is correct |
24 |
Correct |
11 ms |
27720 KB |
Output is correct |
25 |
Correct |
12 ms |
27716 KB |
Output is correct |
26 |
Correct |
11 ms |
27720 KB |
Output is correct |
27 |
Correct |
11 ms |
27604 KB |
Output is correct |
28 |
Correct |
12 ms |
27628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
27604 KB |
Output is correct |
2 |
Correct |
11 ms |
27724 KB |
Output is correct |
3 |
Correct |
10 ms |
27724 KB |
Output is correct |
4 |
Correct |
11 ms |
27712 KB |
Output is correct |
5 |
Correct |
10 ms |
27636 KB |
Output is correct |
6 |
Correct |
11 ms |
27604 KB |
Output is correct |
7 |
Correct |
11 ms |
27604 KB |
Output is correct |
8 |
Correct |
10 ms |
27604 KB |
Output is correct |
9 |
Correct |
10 ms |
27604 KB |
Output is correct |
10 |
Correct |
10 ms |
27604 KB |
Output is correct |
11 |
Correct |
10 ms |
27604 KB |
Output is correct |
12 |
Correct |
10 ms |
27604 KB |
Output is correct |
13 |
Correct |
12 ms |
27604 KB |
Output is correct |
14 |
Correct |
11 ms |
27720 KB |
Output is correct |
15 |
Correct |
11 ms |
27604 KB |
Output is correct |
16 |
Correct |
11 ms |
27720 KB |
Output is correct |
17 |
Correct |
11 ms |
27636 KB |
Output is correct |
18 |
Correct |
11 ms |
27620 KB |
Output is correct |
19 |
Correct |
11 ms |
27716 KB |
Output is correct |
20 |
Correct |
11 ms |
27604 KB |
Output is correct |
21 |
Correct |
11 ms |
27644 KB |
Output is correct |
22 |
Correct |
11 ms |
27604 KB |
Output is correct |
23 |
Correct |
11 ms |
27604 KB |
Output is correct |
24 |
Correct |
11 ms |
27720 KB |
Output is correct |
25 |
Correct |
12 ms |
27716 KB |
Output is correct |
26 |
Correct |
11 ms |
27720 KB |
Output is correct |
27 |
Correct |
11 ms |
27604 KB |
Output is correct |
28 |
Correct |
12 ms |
27628 KB |
Output is correct |
29 |
Correct |
13 ms |
27688 KB |
Output is correct |
30 |
Correct |
10 ms |
27684 KB |
Output is correct |
31 |
Correct |
10 ms |
27604 KB |
Output is correct |
32 |
Correct |
10 ms |
27688 KB |
Output is correct |
33 |
Correct |
11 ms |
27624 KB |
Output is correct |
34 |
Correct |
11 ms |
27720 KB |
Output is correct |
35 |
Correct |
11 ms |
27604 KB |
Output is correct |
36 |
Correct |
11 ms |
27604 KB |
Output is correct |
37 |
Correct |
11 ms |
27604 KB |
Output is correct |
38 |
Correct |
11 ms |
27644 KB |
Output is correct |
39 |
Correct |
11 ms |
27600 KB |
Output is correct |
40 |
Correct |
12 ms |
27656 KB |
Output is correct |
41 |
Correct |
13 ms |
27728 KB |
Output is correct |
42 |
Correct |
12 ms |
27660 KB |
Output is correct |
43 |
Correct |
11 ms |
27720 KB |
Output is correct |
44 |
Correct |
12 ms |
27676 KB |
Output is correct |
45 |
Correct |
11 ms |
27676 KB |
Output is correct |
46 |
Correct |
11 ms |
27628 KB |
Output is correct |
47 |
Correct |
10 ms |
27708 KB |
Output is correct |
48 |
Correct |
11 ms |
27604 KB |
Output is correct |
49 |
Correct |
10 ms |
27664 KB |
Output is correct |
50 |
Correct |
11 ms |
27604 KB |
Output is correct |
51 |
Correct |
13 ms |
27604 KB |
Output is correct |
52 |
Correct |
11 ms |
27604 KB |
Output is correct |
53 |
Correct |
12 ms |
27700 KB |
Output is correct |
54 |
Correct |
11 ms |
27604 KB |
Output is correct |
55 |
Correct |
11 ms |
27700 KB |
Output is correct |
56 |
Correct |
11 ms |
27700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
90396 KB |
Output is correct |
2 |
Correct |
81 ms |
90312 KB |
Output is correct |
3 |
Correct |
82 ms |
90408 KB |
Output is correct |
4 |
Correct |
78 ms |
90352 KB |
Output is correct |
5 |
Correct |
71 ms |
90384 KB |
Output is correct |
6 |
Correct |
69 ms |
90352 KB |
Output is correct |
7 |
Correct |
73 ms |
90308 KB |
Output is correct |
8 |
Correct |
82 ms |
90376 KB |
Output is correct |
9 |
Correct |
73 ms |
90380 KB |
Output is correct |
10 |
Correct |
81 ms |
90384 KB |
Output is correct |
11 |
Correct |
73 ms |
90348 KB |
Output is correct |
12 |
Correct |
73 ms |
90308 KB |
Output is correct |
13 |
Correct |
11 ms |
27712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
27604 KB |
Output is correct |
2 |
Correct |
11 ms |
27724 KB |
Output is correct |
3 |
Correct |
10 ms |
27724 KB |
Output is correct |
4 |
Correct |
11 ms |
27712 KB |
Output is correct |
5 |
Correct |
10 ms |
27636 KB |
Output is correct |
6 |
Correct |
11 ms |
27604 KB |
Output is correct |
7 |
Correct |
11 ms |
27604 KB |
Output is correct |
8 |
Correct |
10 ms |
27604 KB |
Output is correct |
9 |
Correct |
10 ms |
27604 KB |
Output is correct |
10 |
Correct |
10 ms |
27604 KB |
Output is correct |
11 |
Correct |
10 ms |
27604 KB |
Output is correct |
12 |
Correct |
10 ms |
27604 KB |
Output is correct |
13 |
Correct |
12 ms |
27604 KB |
Output is correct |
14 |
Correct |
11 ms |
27720 KB |
Output is correct |
15 |
Correct |
11 ms |
27604 KB |
Output is correct |
16 |
Correct |
11 ms |
27720 KB |
Output is correct |
17 |
Correct |
11 ms |
27636 KB |
Output is correct |
18 |
Correct |
11 ms |
27620 KB |
Output is correct |
19 |
Correct |
11 ms |
27716 KB |
Output is correct |
20 |
Correct |
11 ms |
27604 KB |
Output is correct |
21 |
Correct |
11 ms |
27644 KB |
Output is correct |
22 |
Correct |
11 ms |
27604 KB |
Output is correct |
23 |
Correct |
11 ms |
27604 KB |
Output is correct |
24 |
Correct |
11 ms |
27720 KB |
Output is correct |
25 |
Correct |
12 ms |
27716 KB |
Output is correct |
26 |
Correct |
11 ms |
27720 KB |
Output is correct |
27 |
Correct |
11 ms |
27604 KB |
Output is correct |
28 |
Correct |
12 ms |
27628 KB |
Output is correct |
29 |
Correct |
13 ms |
27688 KB |
Output is correct |
30 |
Correct |
10 ms |
27684 KB |
Output is correct |
31 |
Correct |
10 ms |
27604 KB |
Output is correct |
32 |
Correct |
10 ms |
27688 KB |
Output is correct |
33 |
Correct |
11 ms |
27624 KB |
Output is correct |
34 |
Correct |
11 ms |
27720 KB |
Output is correct |
35 |
Correct |
11 ms |
27604 KB |
Output is correct |
36 |
Correct |
11 ms |
27604 KB |
Output is correct |
37 |
Correct |
11 ms |
27604 KB |
Output is correct |
38 |
Correct |
11 ms |
27644 KB |
Output is correct |
39 |
Correct |
11 ms |
27600 KB |
Output is correct |
40 |
Correct |
12 ms |
27656 KB |
Output is correct |
41 |
Correct |
13 ms |
27728 KB |
Output is correct |
42 |
Correct |
12 ms |
27660 KB |
Output is correct |
43 |
Correct |
11 ms |
27720 KB |
Output is correct |
44 |
Correct |
12 ms |
27676 KB |
Output is correct |
45 |
Correct |
11 ms |
27676 KB |
Output is correct |
46 |
Correct |
11 ms |
27628 KB |
Output is correct |
47 |
Correct |
10 ms |
27708 KB |
Output is correct |
48 |
Correct |
11 ms |
27604 KB |
Output is correct |
49 |
Correct |
10 ms |
27664 KB |
Output is correct |
50 |
Correct |
11 ms |
27604 KB |
Output is correct |
51 |
Correct |
13 ms |
27604 KB |
Output is correct |
52 |
Correct |
11 ms |
27604 KB |
Output is correct |
53 |
Correct |
12 ms |
27700 KB |
Output is correct |
54 |
Correct |
11 ms |
27604 KB |
Output is correct |
55 |
Correct |
11 ms |
27700 KB |
Output is correct |
56 |
Correct |
11 ms |
27700 KB |
Output is correct |
57 |
Correct |
10 ms |
27732 KB |
Output is correct |
58 |
Correct |
10 ms |
27640 KB |
Output is correct |
59 |
Correct |
10 ms |
27720 KB |
Output is correct |
60 |
Correct |
10 ms |
27680 KB |
Output is correct |
61 |
Correct |
10 ms |
27700 KB |
Output is correct |
62 |
Correct |
11 ms |
27732 KB |
Output is correct |
63 |
Correct |
11 ms |
27624 KB |
Output is correct |
64 |
Correct |
11 ms |
27724 KB |
Output is correct |
65 |
Correct |
10 ms |
27724 KB |
Output is correct |
66 |
Correct |
10 ms |
27688 KB |
Output is correct |
67 |
Correct |
11 ms |
27724 KB |
Output is correct |
68 |
Correct |
11 ms |
27732 KB |
Output is correct |
69 |
Correct |
11 ms |
27732 KB |
Output is correct |
70 |
Correct |
10 ms |
27732 KB |
Output is correct |
71 |
Correct |
10 ms |
27724 KB |
Output is correct |
72 |
Correct |
11 ms |
27740 KB |
Output is correct |
73 |
Correct |
11 ms |
27724 KB |
Output is correct |
74 |
Correct |
10 ms |
27728 KB |
Output is correct |
75 |
Correct |
11 ms |
27732 KB |
Output is correct |
76 |
Correct |
10 ms |
27732 KB |
Output is correct |
77 |
Correct |
11 ms |
27732 KB |
Output is correct |
78 |
Correct |
12 ms |
27640 KB |
Output is correct |
79 |
Correct |
11 ms |
27648 KB |
Output is correct |
80 |
Correct |
10 ms |
27732 KB |
Output is correct |
81 |
Correct |
12 ms |
27732 KB |
Output is correct |
82 |
Correct |
11 ms |
27688 KB |
Output is correct |
83 |
Correct |
10 ms |
27656 KB |
Output is correct |
84 |
Correct |
10 ms |
27604 KB |
Output is correct |
85 |
Correct |
10 ms |
27604 KB |
Output is correct |
86 |
Correct |
12 ms |
27604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
27604 KB |
Output is correct |
2 |
Correct |
11 ms |
27724 KB |
Output is correct |
3 |
Correct |
10 ms |
27724 KB |
Output is correct |
4 |
Correct |
11 ms |
27712 KB |
Output is correct |
5 |
Correct |
10 ms |
27636 KB |
Output is correct |
6 |
Correct |
11 ms |
27604 KB |
Output is correct |
7 |
Correct |
11 ms |
27604 KB |
Output is correct |
8 |
Correct |
10 ms |
27604 KB |
Output is correct |
9 |
Correct |
10 ms |
27604 KB |
Output is correct |
10 |
Correct |
10 ms |
27604 KB |
Output is correct |
11 |
Correct |
10 ms |
27604 KB |
Output is correct |
12 |
Correct |
10 ms |
27604 KB |
Output is correct |
13 |
Correct |
12 ms |
27604 KB |
Output is correct |
14 |
Correct |
11 ms |
27720 KB |
Output is correct |
15 |
Correct |
11 ms |
27604 KB |
Output is correct |
16 |
Correct |
11 ms |
27720 KB |
Output is correct |
17 |
Correct |
11 ms |
27636 KB |
Output is correct |
18 |
Correct |
11 ms |
27620 KB |
Output is correct |
19 |
Correct |
11 ms |
27716 KB |
Output is correct |
20 |
Correct |
11 ms |
27604 KB |
Output is correct |
21 |
Correct |
11 ms |
27644 KB |
Output is correct |
22 |
Correct |
11 ms |
27604 KB |
Output is correct |
23 |
Correct |
11 ms |
27604 KB |
Output is correct |
24 |
Correct |
11 ms |
27720 KB |
Output is correct |
25 |
Correct |
12 ms |
27716 KB |
Output is correct |
26 |
Correct |
11 ms |
27720 KB |
Output is correct |
27 |
Correct |
11 ms |
27604 KB |
Output is correct |
28 |
Correct |
12 ms |
27628 KB |
Output is correct |
29 |
Correct |
13 ms |
27688 KB |
Output is correct |
30 |
Correct |
10 ms |
27684 KB |
Output is correct |
31 |
Correct |
10 ms |
27604 KB |
Output is correct |
32 |
Correct |
10 ms |
27688 KB |
Output is correct |
33 |
Correct |
11 ms |
27624 KB |
Output is correct |
34 |
Correct |
11 ms |
27720 KB |
Output is correct |
35 |
Correct |
11 ms |
27604 KB |
Output is correct |
36 |
Correct |
11 ms |
27604 KB |
Output is correct |
37 |
Correct |
11 ms |
27604 KB |
Output is correct |
38 |
Correct |
11 ms |
27644 KB |
Output is correct |
39 |
Correct |
11 ms |
27600 KB |
Output is correct |
40 |
Correct |
12 ms |
27656 KB |
Output is correct |
41 |
Correct |
13 ms |
27728 KB |
Output is correct |
42 |
Correct |
12 ms |
27660 KB |
Output is correct |
43 |
Correct |
11 ms |
27720 KB |
Output is correct |
44 |
Correct |
12 ms |
27676 KB |
Output is correct |
45 |
Correct |
11 ms |
27676 KB |
Output is correct |
46 |
Correct |
11 ms |
27628 KB |
Output is correct |
47 |
Correct |
10 ms |
27708 KB |
Output is correct |
48 |
Correct |
11 ms |
27604 KB |
Output is correct |
49 |
Correct |
10 ms |
27664 KB |
Output is correct |
50 |
Correct |
11 ms |
27604 KB |
Output is correct |
51 |
Correct |
13 ms |
27604 KB |
Output is correct |
52 |
Correct |
11 ms |
27604 KB |
Output is correct |
53 |
Correct |
12 ms |
27700 KB |
Output is correct |
54 |
Correct |
11 ms |
27604 KB |
Output is correct |
55 |
Correct |
11 ms |
27700 KB |
Output is correct |
56 |
Correct |
11 ms |
27700 KB |
Output is correct |
57 |
Correct |
75 ms |
90396 KB |
Output is correct |
58 |
Correct |
81 ms |
90312 KB |
Output is correct |
59 |
Correct |
82 ms |
90408 KB |
Output is correct |
60 |
Correct |
78 ms |
90352 KB |
Output is correct |
61 |
Correct |
71 ms |
90384 KB |
Output is correct |
62 |
Correct |
69 ms |
90352 KB |
Output is correct |
63 |
Correct |
73 ms |
90308 KB |
Output is correct |
64 |
Correct |
82 ms |
90376 KB |
Output is correct |
65 |
Correct |
73 ms |
90380 KB |
Output is correct |
66 |
Correct |
81 ms |
90384 KB |
Output is correct |
67 |
Correct |
73 ms |
90348 KB |
Output is correct |
68 |
Correct |
73 ms |
90308 KB |
Output is correct |
69 |
Correct |
11 ms |
27712 KB |
Output is correct |
70 |
Correct |
10 ms |
27732 KB |
Output is correct |
71 |
Correct |
10 ms |
27640 KB |
Output is correct |
72 |
Correct |
10 ms |
27720 KB |
Output is correct |
73 |
Correct |
10 ms |
27680 KB |
Output is correct |
74 |
Correct |
10 ms |
27700 KB |
Output is correct |
75 |
Correct |
11 ms |
27732 KB |
Output is correct |
76 |
Correct |
11 ms |
27624 KB |
Output is correct |
77 |
Correct |
11 ms |
27724 KB |
Output is correct |
78 |
Correct |
10 ms |
27724 KB |
Output is correct |
79 |
Correct |
10 ms |
27688 KB |
Output is correct |
80 |
Correct |
11 ms |
27724 KB |
Output is correct |
81 |
Correct |
11 ms |
27732 KB |
Output is correct |
82 |
Correct |
11 ms |
27732 KB |
Output is correct |
83 |
Correct |
10 ms |
27732 KB |
Output is correct |
84 |
Correct |
10 ms |
27724 KB |
Output is correct |
85 |
Correct |
11 ms |
27740 KB |
Output is correct |
86 |
Correct |
11 ms |
27724 KB |
Output is correct |
87 |
Correct |
10 ms |
27728 KB |
Output is correct |
88 |
Correct |
11 ms |
27732 KB |
Output is correct |
89 |
Correct |
10 ms |
27732 KB |
Output is correct |
90 |
Correct |
11 ms |
27732 KB |
Output is correct |
91 |
Correct |
12 ms |
27640 KB |
Output is correct |
92 |
Correct |
11 ms |
27648 KB |
Output is correct |
93 |
Correct |
10 ms |
27732 KB |
Output is correct |
94 |
Correct |
12 ms |
27732 KB |
Output is correct |
95 |
Correct |
11 ms |
27688 KB |
Output is correct |
96 |
Correct |
10 ms |
27656 KB |
Output is correct |
97 |
Correct |
10 ms |
27604 KB |
Output is correct |
98 |
Correct |
10 ms |
27604 KB |
Output is correct |
99 |
Correct |
12 ms |
27604 KB |
Output is correct |
100 |
Correct |
47 ms |
41512 KB |
Output is correct |
101 |
Correct |
50 ms |
41504 KB |
Output is correct |
102 |
Correct |
46 ms |
41472 KB |
Output is correct |
103 |
Correct |
45 ms |
41424 KB |
Output is correct |
104 |
Correct |
44 ms |
41520 KB |
Output is correct |
105 |
Correct |
58 ms |
57616 KB |
Output is correct |
106 |
Correct |
59 ms |
57704 KB |
Output is correct |
107 |
Correct |
54 ms |
57664 KB |
Output is correct |
108 |
Correct |
64 ms |
57656 KB |
Output is correct |
109 |
Correct |
62 ms |
57628 KB |
Output is correct |
110 |
Correct |
54 ms |
41448 KB |
Output is correct |
111 |
Correct |
52 ms |
41512 KB |
Output is correct |
112 |
Correct |
49 ms |
41516 KB |
Output is correct |
113 |
Correct |
48 ms |
41488 KB |
Output is correct |
114 |
Correct |
48 ms |
41552 KB |
Output is correct |
115 |
Correct |
98 ms |
90392 KB |
Output is correct |
116 |
Correct |
90 ms |
90304 KB |
Output is correct |
117 |
Correct |
78 ms |
90408 KB |
Output is correct |
118 |
Correct |
80 ms |
90380 KB |
Output is correct |
119 |
Correct |
75 ms |
90420 KB |
Output is correct |
120 |
Correct |
51 ms |
41472 KB |
Output is correct |
121 |
Correct |
50 ms |
41452 KB |
Output is correct |
122 |
Correct |
53 ms |
41520 KB |
Output is correct |
123 |
Correct |
52 ms |
41508 KB |
Output is correct |
124 |
Correct |
55 ms |
64920 KB |
Output is correct |
125 |
Correct |
56 ms |
64936 KB |
Output is correct |
126 |
Correct |
56 ms |
64980 KB |
Output is correct |
127 |
Correct |
58 ms |
64900 KB |
Output is correct |
128 |
Correct |
34 ms |
34900 KB |
Output is correct |
129 |
Correct |
29 ms |
34968 KB |
Output is correct |
130 |
Correct |
24 ms |
34944 KB |
Output is correct |
131 |
Correct |
14 ms |
27780 KB |
Output is correct |