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;
typedef long long ll;
const int N = 2e6 + 12, MOD = 998244353;
string s;
int m, n, col, val[N];
vector<int> st, g[N];
bool ok[N];
int dfs(int v) {
if(v <= col) return val[v];
if(ok[v]) {
return max(dfs(g[v][0]), dfs(g[v][1]));
}
return min(dfs(g[v][0]), dfs(g[v][1]));
}
void test() {
cin >> s;
m = (int)s.size();
for(int i = 0; i < m; i++) {
if(s[i] == '?') {
col++;
}
}
n = col;
for(int i = 0; i < m; i++) {
if(s[i] == '(') {
if(!st.empty()) {
g[st.back()].push_back(n + 1);
}
st.push_back(++n);
if(s[i - 1] == 'x') {
ok[n] = 1;
}
} else if(s[i] == ')') {
st.pop_back();
}
}
int it = 0;
for(int i = col + 1; i <= n; i++) {
int f = (int)g[i].size();
for(int j = 0; j < 2 - f; j++) {
g[i].push_back(++it);
}
}
vector<int> p(col);
iota(p.begin(), p.end(), 1);
set<int> s;
do{
for(int i = 0; i < col; i++) {
val[i + 1] = p[i];
}
s.insert(dfs(col + 1));
}while(next_permutation(p.begin(), p.end()));
cout << (int)s.size() << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
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... |