이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |