#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
string s;
array<int,3>L,R;
array<int,3>solve(int l,int r){
if(l==r) return {1,1,1};
int cur=0;
for(int i=l;i<=r;i++){
if(s[i]=='(') cur++;
if(s[i]==')') cur--;
if(s[i]==','&&cur==1){
L=solve(l+4,i-1);
R=solve(i+1,r-1);
if(s[l+1]=='a'){//max
return {L[0]+R[0],max(L[1]+R[2],R[1]+L[2]),L[2]+R[2]};
}
else{
return {min(L[0],R[0]),L[1]+R[1]-1,L[2]+R[2]};
}
break;
}
}
return {0,0,0};
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>s;
auto ans=solve(0,s.size()-1);
cout<<ans[1]-ans[0]+1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
8676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |