Submission #967999

# Submission time Handle Problem Language Result Execution time Memory
967999 2024-04-23T06:50:06 Z TAhmed33 Fireworks (APIO16_fireworks) C++
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 5e3 + 25;
vector <pair <int, int>> adj[MAXN];
int dp[MAXN][301], n, m;
void dfs (int pos) {
    for (auto j : adj[pos]) {
        dfs(j.first);
    }
    for (int i = 0; i <= 300; i++) {
        int sum = 0;
        for (auto j : adj[pos]) {
int mn = 1e18;
for(int k=0;k<=i;k++)mn=min(mn,abs(j.second-i+k)+dp[j.first][k]);
sum += mn;
            
        }
        dp[pos][i] = sum;
    }
}
signed main () {
    cin >> n >> m;
    n += m;
    for (int i = 2; i <= n; i++) {
        int x, y; cin >> x >> y;
        adj[x].push_back({i, y});
    }
    dfs(1);
    int mn = 1e18;
for (int i = 0; i <= 300; i++) mn = min(mn, dp[1][i]);
cout<<mn;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -