# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867175 | PagodePaiva | Homework (CEOI22_homework) | C++17 | 1014 ms | 54152 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;
string s;
map <int, int> virgulas;
int solve(int l, int r){
if(l == r){
return 1;
}
int con = 0;
int mid;
for(int i = l+4;i <= r;i++){
if(s[i] == '(') con++;
else if(s[i] == ')') con--;
if(con == 0 and s[i] == ','){
mid = i;
break;
}
}
int a = solve(l+4, mid-1);
int b = solve(mid+1, r-1);
if(s[l+1] == 'i'){
return min(a, b);
}
return a+b;
}
int solve2(int l, int r){
// cout << l << ' ' << r << '\n';
if(l == r){
return 1;
}
int con = 0;
int mid = virgulas[l];
int a = solve2(l+4, mid-1);
int b = solve2(mid+1, r-1);
if(s[l+1] == 'a'){
return min(a, b);
}
return a+b;
}
int main(){
cin >> s;
int con = 0;
stack <int> q;
for(int i = 0;i < s.size();i++){
if(s[i] == '?') con++;
if(s[i] == 'm') q.push(i);
if(s[i] == ')') q.pop();
if(s[i] == ',') virgulas[q.top()] = i;
}
int a = solve(0, s.size()-1);
int b = solve2(0, s.size()-1);
b = con-b+1;
cout << b-a+1 << '\n';
}
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... |