QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211763#6742. Leavespsycho#WA 1ms3552kbC++201.2kb2023-10-12 21:01:012023-10-12 21:01:02

Judging History

你现在查看的是最新测评结果

  • [2023-10-12 21:01:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3552kb
  • [2023-10-12 21:01:01]
  • 提交

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(), {(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]));
        }
    }
    for (int i = 0; i + 2 < dp[v].size(); ++i) dp[v + 2] = min(dp[v + 2], dp[v]);
}

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';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

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: 3468kb

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: 3516kb

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: 3472kb

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3516kb

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: 1ms
memory: 3524kb

input:

7 2
1 2 3
1 4 5
1 6 7
2 1
2 2
2 3
2 4

output:

2 1 4 3 

result:

wrong answer 1st numbers differ - expected: '1', found: '2'