답안 #723583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723583 2023-04-14T05:44:53 Z drdilyor Magic Tree (CEOI19_magictree) C++17
22 / 100
463 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,ll>>> 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());
        for (int j = 1; j < (int)fruit[i].size(); j++) {
            fruit[i][j].second += fruit[i][j-1].second;
        }
    }

    auto chop = [&](int i, int day)->ll{
        auto ub = lower_bound(fruit[i].begin(), fruit[i].end(), pair{day+1, -1ll});
        auto lb = lower_bound(fruit[i].begin(), fruit[i].end(), pair{day, -1ll});
        if (ub == fruit[i].begin()) return 0;
        ub--;
        if (lb == fruit[i].begin()) return ub->second;
        return ub->second - (lb-1)->second;
    };


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

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 428 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4564 KB Output is correct
2 Correct 24 ms 4612 KB Output is correct
3 Correct 24 ms 4564 KB Output is correct
4 Runtime error 463 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 150 ms 16188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 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 219 ms 22704 KB Output is correct
11 Correct 142 ms 19592 KB Output is correct
12 Correct 166 ms 28484 KB Output is correct
13 Correct 153 ms 21552 KB Output is correct
14 Correct 151 ms 36684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 419 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 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 25 ms 4564 KB Output is correct
11 Correct 24 ms 4612 KB Output is correct
12 Correct 24 ms 4564 KB Output is correct
13 Runtime error 463 ms 1048576 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 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 428 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -