#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;
struct seg {
int a,b,c;
};
seg cal(string &s,int &x) {
if (s[x]=='?') {
x++;
return {0,1,0};
} else if (s[x+1]=='a') {
x+=4;
seg s1 = cal(s,x);
x++;
seg s2 = cal(s,x);
x++;
seg ans = {s1.a+s2.a+1,0,min(s1.c,s2.c)};
int n = s1.a+s1.b+s1.c+s2.a+s2.b+s2.c;
// cout<<s1.a<<" "<<s1.b<<" "<<s1.c<<" s1\n";
// cout<<s2.a<<" "<<s2.b<<" "<<s2.c<<" s2\n";
// cout<<ans.a<<" "<<n-ans.a-ans.c<<" "<<ans.c<<" "<<x<<"x\n";
return {ans.a,n-ans.a-ans.c,ans.c};
} else {
x+=4;
seg s1 = cal(s,x);
x++;
seg s2 = cal(s,x);
x++;
seg ans = {min(s1.a,s2.a),0,s1.c+s2.c+1};
int n = s1.a+s1.b+s1.c+s2.a+s2.b+s2.c;
// cout<<s1.a<<" "<<s1.b<<" "<<s1.c<<" s1\n";
// cout<<s2.a<<" "<<s2.b<<" "<<s2.c<<" s2\n";
// cout<<ans.a<<" "<<n-ans.a-ans.c<<" "<<ans.c<<" "<<x<<" x\n";
return {ans.a,n-ans.a-ans.c,ans.c};
}
}
int main() {
speed;
string s;
cin>>s;
int now=0;
seg ans=cal(s,now);
cout<<ans.b<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
508 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
508 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
452 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
504 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
504 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
109520 KB |
Output is correct |
2 |
Correct |
112 ms |
109512 KB |
Output is correct |
3 |
Correct |
111 ms |
109532 KB |
Output is correct |
4 |
Correct |
111 ms |
109376 KB |
Output is correct |
5 |
Correct |
107 ms |
109516 KB |
Output is correct |
6 |
Correct |
107 ms |
109516 KB |
Output is correct |
7 |
Correct |
108 ms |
109396 KB |
Output is correct |
8 |
Correct |
109 ms |
109516 KB |
Output is correct |
9 |
Correct |
108 ms |
109516 KB |
Output is correct |
10 |
Correct |
121 ms |
109632 KB |
Output is correct |
11 |
Correct |
109 ms |
109516 KB |
Output is correct |
12 |
Correct |
113 ms |
109392 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
508 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
452 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
504 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
504 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
1 ms |
336 KB |
Output is correct |
58 |
Correct |
1 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
1 ms |
336 KB |
Output is correct |
61 |
Correct |
1 ms |
336 KB |
Output is correct |
62 |
Correct |
1 ms |
336 KB |
Output is correct |
63 |
Correct |
1 ms |
336 KB |
Output is correct |
64 |
Correct |
1 ms |
336 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
2 ms |
336 KB |
Output is correct |
67 |
Correct |
1 ms |
336 KB |
Output is correct |
68 |
Correct |
1 ms |
336 KB |
Output is correct |
69 |
Correct |
1 ms |
380 KB |
Output is correct |
70 |
Correct |
1 ms |
336 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
336 KB |
Output is correct |
73 |
Correct |
1 ms |
336 KB |
Output is correct |
74 |
Correct |
1 ms |
336 KB |
Output is correct |
75 |
Correct |
1 ms |
336 KB |
Output is correct |
76 |
Correct |
2 ms |
336 KB |
Output is correct |
77 |
Correct |
1 ms |
336 KB |
Output is correct |
78 |
Correct |
1 ms |
336 KB |
Output is correct |
79 |
Correct |
1 ms |
336 KB |
Output is correct |
80 |
Correct |
1 ms |
336 KB |
Output is correct |
81 |
Correct |
1 ms |
336 KB |
Output is correct |
82 |
Correct |
1 ms |
336 KB |
Output is correct |
83 |
Correct |
1 ms |
336 KB |
Output is correct |
84 |
Correct |
1 ms |
336 KB |
Output is correct |
85 |
Correct |
1 ms |
508 KB |
Output is correct |
86 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
508 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
452 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
504 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
504 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
129 ms |
109520 KB |
Output is correct |
58 |
Correct |
112 ms |
109512 KB |
Output is correct |
59 |
Correct |
111 ms |
109532 KB |
Output is correct |
60 |
Correct |
111 ms |
109376 KB |
Output is correct |
61 |
Correct |
107 ms |
109516 KB |
Output is correct |
62 |
Correct |
107 ms |
109516 KB |
Output is correct |
63 |
Correct |
108 ms |
109396 KB |
Output is correct |
64 |
Correct |
109 ms |
109516 KB |
Output is correct |
65 |
Correct |
108 ms |
109516 KB |
Output is correct |
66 |
Correct |
121 ms |
109632 KB |
Output is correct |
67 |
Correct |
109 ms |
109516 KB |
Output is correct |
68 |
Correct |
113 ms |
109392 KB |
Output is correct |
69 |
Correct |
1 ms |
336 KB |
Output is correct |
70 |
Correct |
1 ms |
336 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
336 KB |
Output is correct |
73 |
Correct |
1 ms |
336 KB |
Output is correct |
74 |
Correct |
1 ms |
336 KB |
Output is correct |
75 |
Correct |
1 ms |
336 KB |
Output is correct |
76 |
Correct |
1 ms |
336 KB |
Output is correct |
77 |
Correct |
1 ms |
336 KB |
Output is correct |
78 |
Correct |
1 ms |
336 KB |
Output is correct |
79 |
Correct |
2 ms |
336 KB |
Output is correct |
80 |
Correct |
1 ms |
336 KB |
Output is correct |
81 |
Correct |
1 ms |
336 KB |
Output is correct |
82 |
Correct |
1 ms |
380 KB |
Output is correct |
83 |
Correct |
1 ms |
336 KB |
Output is correct |
84 |
Correct |
1 ms |
336 KB |
Output is correct |
85 |
Correct |
1 ms |
336 KB |
Output is correct |
86 |
Correct |
1 ms |
336 KB |
Output is correct |
87 |
Correct |
1 ms |
336 KB |
Output is correct |
88 |
Correct |
1 ms |
336 KB |
Output is correct |
89 |
Correct |
2 ms |
336 KB |
Output is correct |
90 |
Correct |
1 ms |
336 KB |
Output is correct |
91 |
Correct |
1 ms |
336 KB |
Output is correct |
92 |
Correct |
1 ms |
336 KB |
Output is correct |
93 |
Correct |
1 ms |
336 KB |
Output is correct |
94 |
Correct |
1 ms |
336 KB |
Output is correct |
95 |
Correct |
1 ms |
336 KB |
Output is correct |
96 |
Correct |
1 ms |
336 KB |
Output is correct |
97 |
Correct |
1 ms |
336 KB |
Output is correct |
98 |
Correct |
1 ms |
508 KB |
Output is correct |
99 |
Correct |
1 ms |
336 KB |
Output is correct |
100 |
Correct |
37 ms |
15564 KB |
Output is correct |
101 |
Correct |
36 ms |
15440 KB |
Output is correct |
102 |
Correct |
31 ms |
15576 KB |
Output is correct |
103 |
Correct |
32 ms |
15516 KB |
Output is correct |
104 |
Correct |
28 ms |
15560 KB |
Output is correct |
105 |
Correct |
64 ms |
46868 KB |
Output is correct |
106 |
Correct |
69 ms |
47116 KB |
Output is correct |
107 |
Correct |
64 ms |
46808 KB |
Output is correct |
108 |
Correct |
65 ms |
46788 KB |
Output is correct |
109 |
Correct |
60 ms |
46932 KB |
Output is correct |
110 |
Correct |
37 ms |
15436 KB |
Output is correct |
111 |
Correct |
36 ms |
15568 KB |
Output is correct |
112 |
Correct |
31 ms |
15424 KB |
Output is correct |
113 |
Correct |
35 ms |
15452 KB |
Output is correct |
114 |
Correct |
30 ms |
15572 KB |
Output is correct |
115 |
Correct |
127 ms |
109380 KB |
Output is correct |
116 |
Correct |
118 ms |
109692 KB |
Output is correct |
117 |
Correct |
127 ms |
109656 KB |
Output is correct |
118 |
Correct |
121 ms |
109524 KB |
Output is correct |
119 |
Correct |
122 ms |
109388 KB |
Output is correct |
120 |
Correct |
32 ms |
15568 KB |
Output is correct |
121 |
Correct |
32 ms |
15568 KB |
Output is correct |
122 |
Correct |
35 ms |
15444 KB |
Output is correct |
123 |
Correct |
32 ms |
15540 KB |
Output is correct |
124 |
Correct |
67 ms |
62420 KB |
Output is correct |
125 |
Correct |
65 ms |
62548 KB |
Output is correct |
126 |
Correct |
68 ms |
62788 KB |
Output is correct |
127 |
Correct |
68 ms |
62520 KB |
Output is correct |
128 |
Correct |
16 ms |
9432 KB |
Output is correct |
129 |
Correct |
13 ms |
8920 KB |
Output is correct |
130 |
Correct |
12 ms |
9024 KB |
Output is correct |
131 |
Correct |
1 ms |
336 KB |
Output is correct |