Submission #723576

# Submission time Handle Problem Language Result Execution time Memory
723576 2023-04-14T05:34:53 Z drdilyor Magic Tree (CEOI19_magictree) C++17
22 / 100
548 ms 1048576 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main() {
    int n, m, k;
    cin >> n >> m >> k;

    vector<vector<int>> child(n);
    vector par(n, -1);
    for (int i = 1; i < n; i++) {
        cin >> par[i];
        child[--par[i]].push_back(i);
    }

    vector<vector<pair<int,int>>> fruit(n);
    for (int i = 0; i < m; i++) {
        int v, d, w;
        cin >> v >> d >> w;
        fruit[v-1].push_back({d, w});
    }
    for (int i = 0; i < m; i++)
        sort(fruit[i].begin(), fruit[i].end());

    auto chop = [&](auto& chop, int i, int day)->ll{
        ll res = 0;
        for (auto [d, w] : fruit[i])
            if (d == day) res += w;
        return res;
    };


    vector memo(n, vector(k+1, -1));
    auto dp = [&](auto& dp, int i, int day)->ll{
        if (day == 0) return 0;
        if (memo[i][day] !=-1) return memo[i][day];
        ll res1 = chop(chop, i, day);
        for (int e : child[i]) {
            res1 += dp(dp, e, day);
        }
        return memo[i][day] = max(res1, dp(dp, i, day-1));
    };
    cout << dp(dp, 0, k) << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 548 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 4692 KB Output is correct
2 Correct 20 ms 4692 KB Output is correct
3 Correct 21 ms 4692 KB Output is correct
4 Runtime error 491 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 17376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 162 ms 22916 KB Output is correct
11 Correct 155 ms 19832 KB Output is correct
12 Correct 165 ms 25776 KB Output is correct
13 Correct 138 ms 21452 KB Output is correct
14 Correct 147 ms 29136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 413 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 21 ms 4692 KB Output is correct
11 Correct 20 ms 4692 KB Output is correct
12 Correct 21 ms 4692 KB Output is correct
13 Runtime error 491 ms 1048576 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Runtime error 548 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -