# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936472 | sebasvp2005 | Homework (CEOI22_homework) | C++17 | 195 ms | 23004 KiB |
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;
#define ll long long int
#define endl '\n'
void solve(){
stack<int> op;
stack<pair<int,int>> num;
string s;cin>>s;
int n=0;
for(auto e: s)if(e=='?')n++;
for(int i=0;i<s.size(); i++){
if(s[i]=='i'){
op.push(0);
}
if(s[i]=='a'){
op.push(1);
}
if(s[i]=='?') {
num.push({1,n});
}
if(s[i]==')'){
auto a = num.top();num.pop();
auto b = num.top();num.pop();
int o = op.top(); op.pop();
if(o){
num.push({a.first + b.first , max(a.second, b.second)});
}
else{
num.push({min(a.first, b.first), a.second+b.second-n-1});
}
}
}
auto ans = num.top();
cout << ans.second - ans.first + 1 << endl;
}
int main(){
int t=1;//cin>>t;
while(t--){
solve();
}
}
Compilation message (stderr)
# | 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... |