# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838934 | nonono | Homework (CEOI22_homework) | C++14 | 63 ms | 92908 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;
const int mxN = 1000005;
string s;
int n;
vector<vector<int>> adj(mxN);
int type[mxN];
int _min[mxN], _max[mxN];
void dfs(int u) {
if(type[u] == -1) {
_min[u] = 1;
_max[u] = 1;
return ;
}
int vL = adj[u][0];
int vR = adj[u][1];
dfs(vL);
dfs(vR);
if(type[u] == 0) {
_min[u] = min(_min[vL], _min[vR]);
_max[u] = _max[vL] + _max[vR];
}
if(type[u] == 1) {
_min[u] = _min[vL] + _min[vR];
_max[u] = min(_max[vL], _max[vR]);
}
}
signed main() {
#define taskname ""
if(fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
cin >> s;
n = s.size();
vector<int> qu;
int vertex = 0, node = 0;
for(int i = 1; i <= n; i ++) {
if(s[n - i] == ')') {
vertex ++ ;
qu.push_back(vertex);
}
if(s[n - i] == '?') {
vertex ++ ;
node ++ ;
qu.push_back(vertex);
type[vertex] = -1;
}
if(s[n - i] == '(') {
//for(int x : qu) cout << x << " "; cout << "\n";
int vL = qu.back();
qu.pop_back();
int vR = qu.back();
qu.pop_back();
int u = qu.back();
adj[u].push_back(vL);
adj[u].push_back(vR);
if(s.substr(n - i - 3, 3) == "min") type[u] = 0;
if(s.substr(n - i - 3, 3) == "max") type[u] = 1;
}
}
dfs(1);
cout << (node - _max[1] + 1) - _min[1] + 1 << "\n";
return 0;
}
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... |