#include<bits/stdc++.h>
using namespace std;
int type[1000005];
int cur=0,id1,st1,en1,id2,st2,en2;
string s;
struct node{
int st,en,sz;
node(int _st=0,int _en=0,int _sz=0){
st=_st,en=_en,sz=_sz;
}
friend node operator+(node a,node b){
node c;
c.st=a.st+b.st;
c.en=max(a.en+b.sz,b.en+a.sz);
c.sz=a.sz+b.sz;
return c;
}
friend node operator-(node a,node b){
node c;
c.st=min(a.st,b.st);
c.en=a.en+b.en-1;
c.sz=a.sz+b.sz;
return c;
}
}info[10000005];
int dfs(int u,int st){
if(s[st]=='?'){
info[u]=node(1,1,1);
return st;
}else if(s[st+1]=='i'){
id1=cur+1;
st1=st+4;
en1=dfs(++cur,st1);
id2=cur+1;
st2=en1+2;
en2=dfs(++cur,st2);
info[u]=info[id1]-info[id2];
return en2+1;
}else{
id1=cur+1;
st1=st+4;
en1=dfs(++cur,st1);
id2=cur+1;
st2=en1+2;
en2=dfs(++cur,st2);
info[u]=info[id1]+info[id2];
return en2+1;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>s;
dfs(++cur,0);
cout<<info[1].en-info[1].st+1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
119640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
119640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
157916 KB |
Output is correct |
2 |
Correct |
56 ms |
157912 KB |
Output is correct |
3 |
Incorrect |
57 ms |
157896 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
119640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
119640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |