This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#include "debug.cpp"
#else
#define debug(...)
#endif
int NODES = 0;
string s;
int L[10000001],R[10000001],nah[10000001];
int pref[10000001];
vector<int> v[10000001];
int query(int l,int r){
return pref[r]-(l==0?0:pref[l-1]);
}
int rec(int l,int r){
if(l==r){
return nah[l];
}
NODES++;
int p1 = rec(l+4,v[l][1]-2);
int p2 = rec(v[l][1],r-1);
int l1 = l+4 , r1 = v[l][1]-2;
int l2 = v[l][1] , r2 = r-1;
if(s[l+2]=='x'){
R[NODES] = query(l,r)-min(query(l1,r1)-R[p1],query(l2,r2)-R[p2]);
L[NODES] = query(l,r)-(query(l1,r1)-L[p1])-(query(l2,r2)-L[p2]);
}else {
L[NODES] = min(L[p1],L[p2]);
R[NODES] = R[p1]+R[p2]-1;
}
return NODES;
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>s;
int i = 0;
stack<int> st;
while(i<s.size()){
if(s[i]=='m'){
if(!st.empty()){
v[st.top()].push_back(i);
}
st.push(i);
i+=4;
}if(s[i]=='?'){
if(!st.empty()){
v[st.top()].push_back(i);
}
i++;
}if(s[i]==')'){
st.pop();
i++;
}if(s[i]==',')i++;
}
for(int i = 0;i<s.size();i++){
if(s[i]=='?'){
pref[i] = 1;
L[NODES] = 1;
R[NODES] = 1;
nah[i] = NODES;
NODES++;
}
if(i)pref[i]+=pref[i-1];
}
int nah = rec(0,s.size()-1);
cout<<R[nah]-L[nah]+1<<endl;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:40:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | while(i<s.size()){
| ~^~~~~~~~~
Main.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0;i<s.size();i++){
| ~^~~~~~~~~
# | 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... |