QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#145308#6742. LeavesberarchegasWA 4ms16936kbC++172.0kb2023-08-22 05:02:392023-08-22 05:02:40

Judging History

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

  • [2023-08-22 05:02:40]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:16936kb
  • [2023-08-22 05:02:39]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
 
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
    
const int MOD = 1e9 + 7;
const int MAXN = 1e3 + 5;
const ll INF = 2e18;

vector<int> dp[1005][505];
int qtd[1005][505];
int val[MAXN], l[MAXN], r[MAXN], n, m;

void dfs(int node) {
    if (val[node]) {
        for (int i = 0; i <= m; i++) {
            dp[node][i] = {val[node]};
            qtd[node][i] = 0;
        }
        return;
    }
    dfs(l[node]);
    dfs(r[node]);
    for (int i = 0; i <= m; i++) {
        if (!i) {
            dp[node][0] = dp[l[node]][0];
            for (int x : dp[r[node]][0]) dp[node][0].push_back(x);
        }
        else {
            vector<int> a, b;
            int useA = min(i, qtd[l[node]][i]);
            a = dp[l[node]][useA];
            for (int x : dp[r[node]][i - useA]) a.push_back(x);

            int useB = min(i - 1, qtd[r[node]][i - 1]);
            b = dp[r[node]][i - 1];
            for (int x : dp[l[node]][i - 1 - useB]) b.push_back(x);
            
            int qtdA = qtd[l[node]][useA] + qtd[r[node]][i - useA];
            int qtdB = qtd[r[node]][useB] + qtd[l[node]][i - 1 - useB] + 1;
            if (a < b || (a == b && qtdA <= qtdB)) {
                dp[node][i] = a;
                qtd[node][i] = qtdA;
            }
            else {
                dp[node][i] = b;
                qtd[node][i] = qtdB;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    int tipo, a, b;
    for (int i = 1; i <= n; i++) {
        cin >> tipo;
        if (tipo == 1) {
            cin >> a >> b;
            l[i] = a;
            r[i] = b;
        }
        else {
            cin >> val[i];
        }
    }
    dfs(1);
    for (int x : dp[1][m]) cout << x << ' ';
    cout << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 16216kb

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

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: 4ms
memory: 16500kb

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

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: -100
Wrong Answer
time: 3ms
memory: 16300kb

input:

3 1
1 2 3
2 1
2 2

output:

1 2 

result:

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