| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1350259 | AMel0n | Homework (CEOI22_homework) | C++20 | 74 ms | 71336 KiB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
vector<vector<int>> adj;
vector<int> typ;
unordered_set<int> leaf;
pair<int,int> dfs(int v) {
if (typ[v] > 0) {
// if max function and need max return ans min(child 1, child 2)
// if max function and need min return ans of both children
auto [mn1, mx1] = dfs(adj[v][0]);
auto [mn2, mx2] = dfs(adj[v][1]);
return {mn1 + mn2, min(mx1, mx2)};
}
if (typ[v] < 0) {
auto [mn1, mx1] = dfs(adj[v][0]);
auto [mn2, mx2] = dfs(adj[v][1]);
return {min(mn1, mn2), mx1 + mx2};
}
if (!typ[v]) return {1, 1};
// minimum number of larger and smaller values required to make vertex t = k
/*
if min function
if target in the left
right side must be larger - how many larger values do you need?
*/
}
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
string S; cin >> S;
adj.resize(MAXN);
typ.resize(MAXN, -INF);
stack<int> cur;
int i = 0;
int cnt = 0;
while(i < S.size()) {
if (S[i] == ',') {i++; continue;}
if (S[i] == ')') {
cur.pop();
i++;
continue;
}
if (cur.size()) adj[cur.top()].push_back(cnt);
if (S[i] == 'm' && S[i+1] == 'i') {
cur.push(cnt);
typ[cnt++] = -1;
i += 4;
continue;
}
if (S[i] == 'm' && S[i+1] == 'a') {
cur.push(cnt);
typ[cnt++] = 1;
i += 4;
continue;
}
if (S[i] == '?') {
leaf.insert(cnt);
typ[cnt++] = 0;
i++;
}
}
auto [l, r] = dfs(0);
cout << leaf.size() - r + 1 - l + 1;
}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... | ||||
