| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1350261 | AMel0n | Homework (CEOI22_homework) | C++20 | 264 ms | 175540 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e6 + 5;
const ll INF = 1e18;
vector<vector<ll>> adj;
vector<ll> typ;
unordered_set<ll> leaf;
pair<ll,ll> dfs(ll v) {
if (typ[v] > 0) {
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};
// min num of smaller vals required, min num of larger vals required
}
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
string S; cin >> S;
adj.resize(MAXN);
typ.resize(MAXN, -INF);
stack<ll> cur;
ll i = 0;
ll 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... | ||||
