Submission #899289

# Submission time Handle Problem Language Result Execution time Memory
899289 2024-01-05T16:54:32 Z LucaIlie Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
215 ms 197012 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5000;
const long long INF = 1e15;
int n;
int parent[MAX_N + 1], height[MAX_N + 1], cost[MAX_N + 1];
long long dp[MAX_N + 1][MAX_N + 1];
vector<int> children[MAX_N + 1];
map<int, int> mp;

void dfs( int u ) {
    for ( int v: children[u] )
        dfs( v );

    dp[u][n] = INF;
   // printf( "%d\n", u );
    for ( int x = n - 1; x >= 0; x-- ) {
        dp[u][x] = (height[u] == x ? 0 : cost[u]);
        for ( int v: children[u] )
            dp[u][x] += dp[v][x];
        dp[u][x] = min( dp[u][x], dp[u][x + 1] );
       // printf( "%d ", dp[u][x] );
    }
    //printf( "\n" );
}

int main() {
    cin >> n;
    for ( int v = 1; v <= n; v++ )
        cin >> parent[v] >> height[v] >> cost[v];

    for ( int v = 2; v <= n; v++ )
        children[parent[v]].push_back( v );

    for ( int v = 1; v <= n; v++ )
        mp[height[v]] = 1;
    int val = 0;
    for ( auto p: mp )
        mp[p.first] = val++;
    for ( int v = 1; v <= n; v++ )
        height[v] = mp[height[v]];

    dfs( 1 );

    cout << dp[1][0] << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 110 ms 196480 KB Output is correct
6 Correct 87 ms 196304 KB Output is correct
7 Correct 94 ms 196304 KB Output is correct
8 Correct 98 ms 196688 KB Output is correct
9 Correct 96 ms 196296 KB Output is correct
10 Correct 85 ms 196372 KB Output is correct
11 Correct 86 ms 196432 KB Output is correct
12 Correct 71 ms 196948 KB Output is correct
13 Correct 69 ms 196704 KB Output is correct
14 Correct 72 ms 196776 KB Output is correct
15 Correct 69 ms 196688 KB Output is correct
16 Correct 90 ms 196540 KB Output is correct
17 Correct 101 ms 196436 KB Output is correct
18 Correct 88 ms 196300 KB Output is correct
19 Correct 80 ms 196828 KB Output is correct
20 Correct 78 ms 196436 KB Output is correct
21 Correct 78 ms 196524 KB Output is correct
22 Correct 212 ms 196688 KB Output is correct
23 Correct 215 ms 196432 KB Output is correct
24 Correct 137 ms 196688 KB Output is correct
25 Correct 138 ms 196464 KB Output is correct
26 Correct 71 ms 197012 KB Output is correct
27 Correct 82 ms 196692 KB Output is correct
28 Correct 78 ms 196692 KB Output is correct
29 Correct 74 ms 196948 KB Output is correct
30 Correct 73 ms 196816 KB Output is correct
31 Correct 71 ms 196932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 110 ms 196480 KB Output is correct
6 Correct 87 ms 196304 KB Output is correct
7 Correct 94 ms 196304 KB Output is correct
8 Correct 98 ms 196688 KB Output is correct
9 Correct 96 ms 196296 KB Output is correct
10 Correct 85 ms 196372 KB Output is correct
11 Correct 86 ms 196432 KB Output is correct
12 Correct 71 ms 196948 KB Output is correct
13 Correct 69 ms 196704 KB Output is correct
14 Correct 72 ms 196776 KB Output is correct
15 Correct 69 ms 196688 KB Output is correct
16 Correct 90 ms 196540 KB Output is correct
17 Correct 101 ms 196436 KB Output is correct
18 Correct 88 ms 196300 KB Output is correct
19 Correct 80 ms 196828 KB Output is correct
20 Correct 78 ms 196436 KB Output is correct
21 Correct 78 ms 196524 KB Output is correct
22 Correct 212 ms 196688 KB Output is correct
23 Correct 215 ms 196432 KB Output is correct
24 Correct 137 ms 196688 KB Output is correct
25 Correct 138 ms 196464 KB Output is correct
26 Correct 71 ms 197012 KB Output is correct
27 Correct 82 ms 196692 KB Output is correct
28 Correct 78 ms 196692 KB Output is correct
29 Correct 74 ms 196948 KB Output is correct
30 Correct 73 ms 196816 KB Output is correct
31 Correct 71 ms 196932 KB Output is correct
32 Incorrect 47 ms 124008 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 110 ms 196480 KB Output is correct
6 Correct 87 ms 196304 KB Output is correct
7 Correct 94 ms 196304 KB Output is correct
8 Correct 98 ms 196688 KB Output is correct
9 Correct 96 ms 196296 KB Output is correct
10 Correct 85 ms 196372 KB Output is correct
11 Correct 86 ms 196432 KB Output is correct
12 Correct 71 ms 196948 KB Output is correct
13 Correct 69 ms 196704 KB Output is correct
14 Correct 72 ms 196776 KB Output is correct
15 Correct 69 ms 196688 KB Output is correct
16 Correct 90 ms 196540 KB Output is correct
17 Correct 101 ms 196436 KB Output is correct
18 Correct 88 ms 196300 KB Output is correct
19 Correct 80 ms 196828 KB Output is correct
20 Correct 78 ms 196436 KB Output is correct
21 Correct 78 ms 196524 KB Output is correct
22 Correct 212 ms 196688 KB Output is correct
23 Correct 215 ms 196432 KB Output is correct
24 Correct 137 ms 196688 KB Output is correct
25 Correct 138 ms 196464 KB Output is correct
26 Correct 71 ms 197012 KB Output is correct
27 Correct 82 ms 196692 KB Output is correct
28 Correct 78 ms 196692 KB Output is correct
29 Correct 74 ms 196948 KB Output is correct
30 Correct 73 ms 196816 KB Output is correct
31 Correct 71 ms 196932 KB Output is correct
32 Incorrect 47 ms 124008 KB Output isn't correct
33 Halted 0 ms 0 KB -