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>
#define x first
#define y second
#define sz(v) (int)v.size()
#define pb push_back
#define nl "\n"
using namespace std;
const int N = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
int n, pos[N], p[N], e[N];
string s;
int calc(int l, int r) {
if(l == r) {
return p[pos[l]];
}
bool tp = (s[l + 1] == 'a');
int mid = e[l];
if(tp) return max(calc(l + 4, mid - 1), calc(mid + 1, r - 1));
else return min(calc(l + 4, mid - 1), calc(mid + 1, r - 1));
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> s;
for(int i = 0; i < sz(s); ++i) {
if(s[i] == '?') {
pos[i] = ++n;
}
}
stack<int> st;
for(int i = 0; i < sz(s); ++i) {
if(s[i] == 'm') st.push(i);
if(s[i] == ',') {
assert(!st.empty());
e[st.top()] = i;
st.pop();
}
}
for(int i = 1; i <= n; ++i) p[i] = i;
set<int> se;
do {
int val = calc(0, sz(s) - 1);
se.insert(val);
} while(next_permutation(p + 1, p + 1 + n));
cout << sz(se) << nl;
return 0;
}
# | 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... |