#include <bits/stdc++.h>
using namespace std;
struct Node {
int st, dr;
int sz;
Node () {
st = 1, dr = 0;
sz = 0;
}
};
string S;
int pos = 0;
Node Join (Node a, Node b, bool op) {
Node ans;
ans.sz = a.sz + b.sz;
if (op == false) {
ans.st = min(a.st, b.st);
ans.dr = a.dr + b.dr - 1;
}
else {
ans.st = min(b.dr + a.st, b.st + a.dr);
ans.dr = max(a.dr + b.sz, a.sz + b.dr);
}
ans.sz = a.sz + b.sz;
return ans;
}
Node Eval () {
if (S[pos] == '?') {
Node ans;
ans.st = 1, ans.dr = 1, ans.sz = 1;
return ans;
}
bool op = 0;
if (S[pos] == 'm' && S[pos+1] == 'a' && S[pos+2] == 'x') op = 1;
Node a, b;
pos += 4;
a = Eval();
pos += 2;
b = Eval();
++ pos;
return Join(a, b, op);
}
int main () {
cin >> S;
Node ans = Eval();
cout << ans.dr - ans.st + 1 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
90340 KB |
Output is correct |
2 |
Correct |
198 ms |
90836 KB |
Output is correct |
3 |
Correct |
201 ms |
90456 KB |
Output is correct |
4 |
Correct |
199 ms |
92132 KB |
Output is correct |
5 |
Correct |
193 ms |
91800 KB |
Output is correct |
6 |
Correct |
192 ms |
92084 KB |
Output is correct |
7 |
Correct |
195 ms |
91392 KB |
Output is correct |
8 |
Correct |
197 ms |
91596 KB |
Output is correct |
9 |
Correct |
196 ms |
90760 KB |
Output is correct |
10 |
Correct |
210 ms |
90316 KB |
Output is correct |
11 |
Correct |
195 ms |
92364 KB |
Output is correct |
12 |
Correct |
202 ms |
90716 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |