QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211750 | #6742. Leaves | psycho# | WA | 0ms | 3924kb | C++20 | 1.2kb | 2023-10-12 20:54:30 | 2023-10-12 20:54:31 |
Judging History
answer
#include <bits/stdc++.h>
template<class t> using vc = std::vector<t>;
using namespace std;
typedef long long ll;
const int N = 1005;
int a[N];
int l[N], r[N];
vc<vc<int>> dp[N];
vc<int> merge(vc<int> &a, vc<int> &b) {
vc<int> ans;
ans.insert(ans.end(), a.begin(), a.end());
ans.insert(ans.end(), b.begin(), b.end());
ans.shrink_to_fit();
return ans;
}
void dfs(int v) {
if (!l[v]) return void(dp[v] = {{a[v]}});
dfs(l[v]), dfs(r[v]);
dp[v].resize(dp[l[v]].size() + dp[r[v]].size() + 1, {(int) 1e9});
for (int d1 = 0; d1 < dp[l[v]].size(); ++d1) {
for (int d2 = 0; d2 < dp[r[v]].size(); ++d2) {
dp[v][d1 + d2] = min(dp[v][d1 + d2], merge(dp[l[v]][d1], dp[r[v]][d2]));
dp[v][d1 + d2 + 1] = min(dp[v][d1 + d2 + 1], merge(dp[r[v]][d2], dp[l[v]][d1]));
}
}
}
int main() {
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 1, t; i <= n && cin >> t; ++i) {
if (t == 1) cin >> l[i] >> r[i];
else cin >> a[i];
}
dfs(1);
for (auto i : dp[1][m]) cout << i << ' ';
cout << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
3 0 1 2 3 2 1 2 2
output:
1 2
result:
ok 2 number(s): "1 2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
7 1 1 2 3 1 4 5 1 6 7 2 4 2 2 2 3 2 1
output:
2 4 3 1
result:
ok 4 number(s): "2 4 3 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
7 2 1 2 3 1 4 5 1 6 7 2 4 2 2 2 3 2 1
output:
1 3 4 2
result:
ok 4 number(s): "1 3 4 2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
3 1 1 2 3 2 1 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3920kb
input:
7 2 1 2 3 1 4 5 1 6 7 2 1 2 2 2 3 2 4
output:
1 2 1000000000
result:
wrong answer 3rd numbers differ - expected: '3', found: '1000000000'