QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346446 | #6742. Leaves | wzihan | WA | 0ms | 3560kb | C++20 | 1.3kb | 2024-03-08 15:21:25 | 2024-03-08 15:21:27 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<array<int, 2>> child(n, {-1, -1});
vector<int> a(n);
for (int i = 0; i < n; i++) {
int t;
cin >> t;
if (t == 1) {
int l, r;
cin >> l >> r;
l--, r--;
child[i] = {l, r};
} else {
cin >> a[i];
}
}
auto dfs = [&](auto self, int u) {
vector<vector<int>> dp;
if (child[u][0] == -1) {
dp = {{a[u]}};
return dp;
}
auto l = self(self, child[u][0]);
auto r = self(self, child[u][1]);
dp.resize(l.size() + r.size());
for (int x = 0; x < l.size(); x++) {
for (int y = 0; y < r.size(); y++) {
auto a = l[x];
a.insert(a.end(), r[y].begin(), r[y].end());
if (dp[x + y].empty() || a < dp[x + y]) {
dp[x + y] = a;
}
auto b = r[y];
b.insert(b.end(), l[x].begin(), l[x].end());
if (dp[x + y + 1].empty() || b < dp[x + y + 1]) {
dp[x + y + 1] = b;
}
}
}
return dp;
};
auto dp = dfs(dfs, 0);
auto ans = dp[m];
for (int i = m; i >= 0; i -= 2) {
ans = min(ans, dp[i]);
}
for (int i = 0; i < ans.size(); i++) {
cout << i << " \n"[i == ans.size() - 1];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3560kb
input:
3 0 1 2 3 2 1 2 2
output:
0 1
result:
wrong answer 1st numbers differ - expected: '1', found: '0'