Submission #1024237

# Submission time Handle Problem Language Result Execution time Memory
1024237 2024-07-15T17:59:10 Z vjudge1 Fireworks (APIO16_fireworks) C++17
19 / 100
13 ms 1204 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;

const ll MAXN = 3E2+16, INF = ll(1E18)+16;
vii adj[MAXN];
ll dp[MAXN][MAXN];

void dfs (ll u) {
    if (adj[u].empty()) iota(dp[u], dp[u]+MAXN, 0);
    for (auto [v, w] : adj[u]) {
        dfs(v);
        for (ll i = 0; i <= 300; i++) { // wanted expl time
            ll minN = INF;
            for (ll mod = 0; mod <= i; mod++) { // mod on w
                minN = min(minN, dp[v][i-mod]+abs(mod-w));
            }
            dp[u][i] += minN;
        }
    }
}

int main () {
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    for (ll v = 1; v < n+m; v++) {
        ll u, w;
        cin >> u >> w;
        u--;
        adj[u].push_back({ v, w });
    }
    dfs(0);
    ll ans = INF;
    for (ll i = 0; i <= 300; i++) {
        ans = min(ans, dp[0][i]);
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 7 ms 860 KB Output is correct
9 Correct 7 ms 796 KB Output is correct
10 Correct 8 ms 860 KB Output is correct
11 Correct 9 ms 860 KB Output is correct
12 Correct 10 ms 880 KB Output is correct
13 Correct 10 ms 1116 KB Output is correct
14 Correct 11 ms 1116 KB Output is correct
15 Correct 11 ms 1088 KB Output is correct
16 Correct 11 ms 1116 KB Output is correct
17 Correct 11 ms 1112 KB Output is correct
18 Correct 11 ms 1116 KB Output is correct
19 Correct 13 ms 1204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -