QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202386#6742. Leavesreal_sigma_team#WA 0ms3848kbC++141.2kb2023-10-06 00:01:202023-10-06 00:01:20

Judging History

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

  • [2023-10-06 00:01:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3848kb
  • [2023-10-06 00:01:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()

vector<int> operator+(vector<int> a, vector<int> b) {
    for (auto i : b) a.push_back(i);
    return a;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> a(n, -1);
    vector<int> l(n, -1), r(n, -1);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            cin >> l[i] >> r[i];
            --l[i], --r[i];
        } else {
            cin >> a[i];
        }
    }
    vector<vector<vector<int>>> dp(n);
    auto dfs = [&](auto dfs, int u) -> void {
        if (a[u] != -1) {
            dp[u] = {{a[u]}};
            return;
        }
        dfs(dfs, l[u]);
        dfs(dfs, r[u]);
        dp[u].resize(dp[l[u]].size() + dp[r[u]].size(), {(int)1e9 + 1});
        for (int i = 0; i < dp[l[u]].size(); ++i) {
            for (int j = 0; j < dp[r[u]].size(); ++j) {
                dp[u][i + j] = min(dp[u][i + j], dp[l[u]][i] + dp[r[u]][j]);
                dp[u][i + j + 1] = min(dp[u][i + j + 1], dp[r[u]][j] + dp[l[u]][i]);
            }
        }
    };
    dfs(dfs, 0);
    for (auto i : dp[0][m]) cout << i << ' ';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

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

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

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'