답안 #897326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897326 2024-01-02T22:32:33 Z juliany2 Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
74 ms 197204 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()

const int N = 5007;
int n;
int h[N], c[N];
vector<int> adj[N];
ll dp[N][N];

void dfs(int v = 1) {
    for (int u : adj[v]) {
        dfs(u);

        for (int i = 1; i <= n; i++)
            dp[v][i] += dp[u][i];
    }

    for (int i = 1; i <= h[v]; i++)
        dp[v][i] = max(dp[v][i], dp[v][h[v]] + c[v]);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

    cin >> n;

    ll sum = 0;
    vector<int> cmp = {0};
    for (int i = 1; i <= n; i++) {
        int p;
        cin >> p >> h[i] >> c[i];

        if (i != 1)
            adj[p].push_back(i);

        cmp.push_back(h[i]);
        sum += c[i];
    }

    sort(all(cmp));
    cmp.erase(unique(all(cmp)), cmp.end());

    for (int i = 1; i <= n; i++)
        h[i] = lower_bound(all(cmp), h[i]) - cmp.begin();

    dfs();

    cout << sum - *max_element(dp[1] + 1, dp[1] + n + 1) << '\n';

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 612 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 74 ms 168096 KB Output is correct
6 Correct 50 ms 137000 KB Output is correct
7 Correct 44 ms 137296 KB Output is correct
8 Correct 64 ms 169112 KB Output is correct
9 Correct 43 ms 130128 KB Output is correct
10 Correct 47 ms 141932 KB Output is correct
11 Correct 41 ms 133204 KB Output is correct
12 Correct 54 ms 197200 KB Output is correct
13 Correct 33 ms 197004 KB Output is correct
14 Correct 43 ms 196856 KB Output is correct
15 Correct 33 ms 196956 KB Output is correct
16 Correct 54 ms 157264 KB Output is correct
17 Correct 30 ms 110420 KB Output is correct
18 Correct 29 ms 109372 KB Output is correct
19 Correct 55 ms 158036 KB Output is correct
20 Correct 29 ms 110676 KB Output is correct
21 Correct 29 ms 109660 KB Output is correct
22 Correct 63 ms 117672 KB Output is correct
23 Correct 24 ms 23120 KB Output is correct
24 Correct 54 ms 157268 KB Output is correct
25 Correct 29 ms 110172 KB Output is correct
26 Correct 43 ms 197204 KB Output is correct
27 Correct 50 ms 132944 KB Output is correct
28 Correct 45 ms 146780 KB Output is correct
29 Correct 47 ms 170520 KB Output is correct
30 Correct 52 ms 196852 KB Output is correct
31 Correct 43 ms 196860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 612 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 74 ms 168096 KB Output is correct
6 Correct 50 ms 137000 KB Output is correct
7 Correct 44 ms 137296 KB Output is correct
8 Correct 64 ms 169112 KB Output is correct
9 Correct 43 ms 130128 KB Output is correct
10 Correct 47 ms 141932 KB Output is correct
11 Correct 41 ms 133204 KB Output is correct
12 Correct 54 ms 197200 KB Output is correct
13 Correct 33 ms 197004 KB Output is correct
14 Correct 43 ms 196856 KB Output is correct
15 Correct 33 ms 196956 KB Output is correct
16 Correct 54 ms 157264 KB Output is correct
17 Correct 30 ms 110420 KB Output is correct
18 Correct 29 ms 109372 KB Output is correct
19 Correct 55 ms 158036 KB Output is correct
20 Correct 29 ms 110676 KB Output is correct
21 Correct 29 ms 109660 KB Output is correct
22 Correct 63 ms 117672 KB Output is correct
23 Correct 24 ms 23120 KB Output is correct
24 Correct 54 ms 157268 KB Output is correct
25 Correct 29 ms 110172 KB Output is correct
26 Correct 43 ms 197204 KB Output is correct
27 Correct 50 ms 132944 KB Output is correct
28 Correct 45 ms 146780 KB Output is correct
29 Correct 47 ms 170520 KB Output is correct
30 Correct 52 ms 196852 KB Output is correct
31 Correct 43 ms 196860 KB Output is correct
32 Correct 61 ms 172628 KB Output is correct
33 Runtime error 6 ms 1624 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 612 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 74 ms 168096 KB Output is correct
6 Correct 50 ms 137000 KB Output is correct
7 Correct 44 ms 137296 KB Output is correct
8 Correct 64 ms 169112 KB Output is correct
9 Correct 43 ms 130128 KB Output is correct
10 Correct 47 ms 141932 KB Output is correct
11 Correct 41 ms 133204 KB Output is correct
12 Correct 54 ms 197200 KB Output is correct
13 Correct 33 ms 197004 KB Output is correct
14 Correct 43 ms 196856 KB Output is correct
15 Correct 33 ms 196956 KB Output is correct
16 Correct 54 ms 157264 KB Output is correct
17 Correct 30 ms 110420 KB Output is correct
18 Correct 29 ms 109372 KB Output is correct
19 Correct 55 ms 158036 KB Output is correct
20 Correct 29 ms 110676 KB Output is correct
21 Correct 29 ms 109660 KB Output is correct
22 Correct 63 ms 117672 KB Output is correct
23 Correct 24 ms 23120 KB Output is correct
24 Correct 54 ms 157268 KB Output is correct
25 Correct 29 ms 110172 KB Output is correct
26 Correct 43 ms 197204 KB Output is correct
27 Correct 50 ms 132944 KB Output is correct
28 Correct 45 ms 146780 KB Output is correct
29 Correct 47 ms 170520 KB Output is correct
30 Correct 52 ms 196852 KB Output is correct
31 Correct 43 ms 196860 KB Output is correct
32 Correct 61 ms 172628 KB Output is correct
33 Runtime error 6 ms 1624 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -