#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
// 0 -> ?, 1 -> min, 2 -> max
int n, p, T[MAXN], L[MAXN], R[MAXN], sz[MAXN];
string s;
vector<int> adj[MAXN];
inline char read() {
return s[p++];
}
int build() {
if (read() == '?') return ++n; // m / ?
char t = read(); // i / a
int v = ++n;
T[v] = (t == 'i' ? 1 : 2);
read(); // n / x
read(); // (
int a = build();
read(); // ,
int b = build();
read(); // )
adj[v].push_back(a);
adj[v].push_back(b);
return v;
}
void dfs(int v) {
if (!T[v]) {
L[v] = R[v] = sz[v] = 1;
return;
}
int a = adj[v][0], b = adj[v][1];
dfs(a);
dfs(b);
sz[v] = sz[a] + sz[b];
if (T[v] == 2) {
L[v] = L[a] + L[b];
R[v] = max(R[a] + sz[b], R[b] + sz[a]);
} else {
R[v] = R[a] + R[b] - 1;
L[v] = min(L[a], L[b]);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> s;
int v = build();
dfs(v);
cout << R[v] - L[v] + 1 << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23768 KB |
Output is correct |
5 |
Correct |
12 ms |
23816 KB |
Output is correct |
6 |
Correct |
12 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23816 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23772 KB |
Output is correct |
10 |
Correct |
12 ms |
23812 KB |
Output is correct |
11 |
Correct |
12 ms |
23724 KB |
Output is correct |
12 |
Correct |
11 ms |
23824 KB |
Output is correct |
13 |
Correct |
14 ms |
23820 KB |
Output is correct |
14 |
Correct |
12 ms |
23772 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23816 KB |
Output is correct |
17 |
Correct |
13 ms |
23812 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
13 ms |
23852 KB |
Output is correct |
20 |
Correct |
14 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23736 KB |
Output is correct |
23 |
Correct |
13 ms |
23724 KB |
Output is correct |
24 |
Correct |
12 ms |
23812 KB |
Output is correct |
25 |
Correct |
13 ms |
23764 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
12 ms |
23808 KB |
Output is correct |
28 |
Correct |
12 ms |
23752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23768 KB |
Output is correct |
5 |
Correct |
12 ms |
23816 KB |
Output is correct |
6 |
Correct |
12 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23816 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23772 KB |
Output is correct |
10 |
Correct |
12 ms |
23812 KB |
Output is correct |
11 |
Correct |
12 ms |
23724 KB |
Output is correct |
12 |
Correct |
11 ms |
23824 KB |
Output is correct |
13 |
Correct |
14 ms |
23820 KB |
Output is correct |
14 |
Correct |
12 ms |
23772 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23816 KB |
Output is correct |
17 |
Correct |
13 ms |
23812 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
13 ms |
23852 KB |
Output is correct |
20 |
Correct |
14 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23736 KB |
Output is correct |
23 |
Correct |
13 ms |
23724 KB |
Output is correct |
24 |
Correct |
12 ms |
23812 KB |
Output is correct |
25 |
Correct |
13 ms |
23764 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
12 ms |
23808 KB |
Output is correct |
28 |
Correct |
12 ms |
23752 KB |
Output is correct |
29 |
Correct |
13 ms |
23804 KB |
Output is correct |
30 |
Correct |
13 ms |
23764 KB |
Output is correct |
31 |
Correct |
12 ms |
23828 KB |
Output is correct |
32 |
Correct |
12 ms |
23740 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23764 KB |
Output is correct |
35 |
Correct |
13 ms |
23764 KB |
Output is correct |
36 |
Correct |
13 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23808 KB |
Output is correct |
38 |
Correct |
12 ms |
23764 KB |
Output is correct |
39 |
Correct |
14 ms |
23764 KB |
Output is correct |
40 |
Correct |
15 ms |
23812 KB |
Output is correct |
41 |
Correct |
12 ms |
23808 KB |
Output is correct |
42 |
Correct |
13 ms |
23732 KB |
Output is correct |
43 |
Correct |
12 ms |
23828 KB |
Output is correct |
44 |
Correct |
13 ms |
23720 KB |
Output is correct |
45 |
Correct |
13 ms |
23764 KB |
Output is correct |
46 |
Correct |
13 ms |
23808 KB |
Output is correct |
47 |
Correct |
14 ms |
23764 KB |
Output is correct |
48 |
Correct |
13 ms |
23828 KB |
Output is correct |
49 |
Correct |
14 ms |
23708 KB |
Output is correct |
50 |
Correct |
12 ms |
23732 KB |
Output is correct |
51 |
Correct |
12 ms |
23812 KB |
Output is correct |
52 |
Correct |
12 ms |
23812 KB |
Output is correct |
53 |
Correct |
13 ms |
23764 KB |
Output is correct |
54 |
Correct |
13 ms |
23812 KB |
Output is correct |
55 |
Correct |
12 ms |
23764 KB |
Output is correct |
56 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
282 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23768 KB |
Output is correct |
5 |
Correct |
12 ms |
23816 KB |
Output is correct |
6 |
Correct |
12 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23816 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23772 KB |
Output is correct |
10 |
Correct |
12 ms |
23812 KB |
Output is correct |
11 |
Correct |
12 ms |
23724 KB |
Output is correct |
12 |
Correct |
11 ms |
23824 KB |
Output is correct |
13 |
Correct |
14 ms |
23820 KB |
Output is correct |
14 |
Correct |
12 ms |
23772 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23816 KB |
Output is correct |
17 |
Correct |
13 ms |
23812 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
13 ms |
23852 KB |
Output is correct |
20 |
Correct |
14 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23736 KB |
Output is correct |
23 |
Correct |
13 ms |
23724 KB |
Output is correct |
24 |
Correct |
12 ms |
23812 KB |
Output is correct |
25 |
Correct |
13 ms |
23764 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
12 ms |
23808 KB |
Output is correct |
28 |
Correct |
12 ms |
23752 KB |
Output is correct |
29 |
Correct |
13 ms |
23804 KB |
Output is correct |
30 |
Correct |
13 ms |
23764 KB |
Output is correct |
31 |
Correct |
12 ms |
23828 KB |
Output is correct |
32 |
Correct |
12 ms |
23740 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23764 KB |
Output is correct |
35 |
Correct |
13 ms |
23764 KB |
Output is correct |
36 |
Correct |
13 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23808 KB |
Output is correct |
38 |
Correct |
12 ms |
23764 KB |
Output is correct |
39 |
Correct |
14 ms |
23764 KB |
Output is correct |
40 |
Correct |
15 ms |
23812 KB |
Output is correct |
41 |
Correct |
12 ms |
23808 KB |
Output is correct |
42 |
Correct |
13 ms |
23732 KB |
Output is correct |
43 |
Correct |
12 ms |
23828 KB |
Output is correct |
44 |
Correct |
13 ms |
23720 KB |
Output is correct |
45 |
Correct |
13 ms |
23764 KB |
Output is correct |
46 |
Correct |
13 ms |
23808 KB |
Output is correct |
47 |
Correct |
14 ms |
23764 KB |
Output is correct |
48 |
Correct |
13 ms |
23828 KB |
Output is correct |
49 |
Correct |
14 ms |
23708 KB |
Output is correct |
50 |
Correct |
12 ms |
23732 KB |
Output is correct |
51 |
Correct |
12 ms |
23812 KB |
Output is correct |
52 |
Correct |
12 ms |
23812 KB |
Output is correct |
53 |
Correct |
13 ms |
23764 KB |
Output is correct |
54 |
Correct |
13 ms |
23812 KB |
Output is correct |
55 |
Correct |
12 ms |
23764 KB |
Output is correct |
56 |
Correct |
12 ms |
23764 KB |
Output is correct |
57 |
Correct |
13 ms |
23904 KB |
Output is correct |
58 |
Correct |
14 ms |
23892 KB |
Output is correct |
59 |
Correct |
13 ms |
23892 KB |
Output is correct |
60 |
Correct |
13 ms |
23892 KB |
Output is correct |
61 |
Correct |
12 ms |
23828 KB |
Output is correct |
62 |
Correct |
13 ms |
23816 KB |
Output is correct |
63 |
Correct |
14 ms |
23896 KB |
Output is correct |
64 |
Correct |
13 ms |
23892 KB |
Output is correct |
65 |
Correct |
13 ms |
23860 KB |
Output is correct |
66 |
Correct |
12 ms |
23932 KB |
Output is correct |
67 |
Correct |
14 ms |
23892 KB |
Output is correct |
68 |
Correct |
15 ms |
23864 KB |
Output is correct |
69 |
Correct |
15 ms |
23808 KB |
Output is correct |
70 |
Correct |
14 ms |
23892 KB |
Output is correct |
71 |
Correct |
14 ms |
23892 KB |
Output is correct |
72 |
Correct |
13 ms |
23892 KB |
Output is correct |
73 |
Correct |
13 ms |
23988 KB |
Output is correct |
74 |
Correct |
14 ms |
23892 KB |
Output is correct |
75 |
Correct |
13 ms |
23892 KB |
Output is correct |
76 |
Correct |
13 ms |
23892 KB |
Output is correct |
77 |
Correct |
12 ms |
23892 KB |
Output is correct |
78 |
Correct |
11 ms |
23892 KB |
Output is correct |
79 |
Correct |
15 ms |
23892 KB |
Output is correct |
80 |
Correct |
11 ms |
23892 KB |
Output is correct |
81 |
Correct |
16 ms |
23892 KB |
Output is correct |
82 |
Correct |
12 ms |
23836 KB |
Output is correct |
83 |
Correct |
11 ms |
23764 KB |
Output is correct |
84 |
Correct |
14 ms |
23764 KB |
Output is correct |
85 |
Correct |
12 ms |
23764 KB |
Output is correct |
86 |
Correct |
13 ms |
23812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23792 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23768 KB |
Output is correct |
5 |
Correct |
12 ms |
23816 KB |
Output is correct |
6 |
Correct |
12 ms |
23816 KB |
Output is correct |
7 |
Correct |
12 ms |
23816 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23772 KB |
Output is correct |
10 |
Correct |
12 ms |
23812 KB |
Output is correct |
11 |
Correct |
12 ms |
23724 KB |
Output is correct |
12 |
Correct |
11 ms |
23824 KB |
Output is correct |
13 |
Correct |
14 ms |
23820 KB |
Output is correct |
14 |
Correct |
12 ms |
23772 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23816 KB |
Output is correct |
17 |
Correct |
13 ms |
23812 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
13 ms |
23852 KB |
Output is correct |
20 |
Correct |
14 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23736 KB |
Output is correct |
23 |
Correct |
13 ms |
23724 KB |
Output is correct |
24 |
Correct |
12 ms |
23812 KB |
Output is correct |
25 |
Correct |
13 ms |
23764 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
12 ms |
23808 KB |
Output is correct |
28 |
Correct |
12 ms |
23752 KB |
Output is correct |
29 |
Correct |
13 ms |
23804 KB |
Output is correct |
30 |
Correct |
13 ms |
23764 KB |
Output is correct |
31 |
Correct |
12 ms |
23828 KB |
Output is correct |
32 |
Correct |
12 ms |
23740 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23764 KB |
Output is correct |
35 |
Correct |
13 ms |
23764 KB |
Output is correct |
36 |
Correct |
13 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23808 KB |
Output is correct |
38 |
Correct |
12 ms |
23764 KB |
Output is correct |
39 |
Correct |
14 ms |
23764 KB |
Output is correct |
40 |
Correct |
15 ms |
23812 KB |
Output is correct |
41 |
Correct |
12 ms |
23808 KB |
Output is correct |
42 |
Correct |
13 ms |
23732 KB |
Output is correct |
43 |
Correct |
12 ms |
23828 KB |
Output is correct |
44 |
Correct |
13 ms |
23720 KB |
Output is correct |
45 |
Correct |
13 ms |
23764 KB |
Output is correct |
46 |
Correct |
13 ms |
23808 KB |
Output is correct |
47 |
Correct |
14 ms |
23764 KB |
Output is correct |
48 |
Correct |
13 ms |
23828 KB |
Output is correct |
49 |
Correct |
14 ms |
23708 KB |
Output is correct |
50 |
Correct |
12 ms |
23732 KB |
Output is correct |
51 |
Correct |
12 ms |
23812 KB |
Output is correct |
52 |
Correct |
12 ms |
23812 KB |
Output is correct |
53 |
Correct |
13 ms |
23764 KB |
Output is correct |
54 |
Correct |
13 ms |
23812 KB |
Output is correct |
55 |
Correct |
12 ms |
23764 KB |
Output is correct |
56 |
Correct |
12 ms |
23764 KB |
Output is correct |
57 |
Runtime error |
282 ms |
524288 KB |
Execution killed with signal 9 |
58 |
Halted |
0 ms |
0 KB |
- |