Submission #960141

# Submission time Handle Problem Language Result Execution time Memory
960141 2024-04-09T18:02:54 Z MinaRagy06 Fireworks (APIO16_fireworks) C++17
0 / 100
2 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 305;
const ll inf = 2e18;
vector<array<int, 2>> adj[N];
ll dp[N][N];
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, m;
	cin >> n >> m;
	n += m;
	for (int i = 2; i <= n; i++) {
		int p, c;
		cin >> p >> c;
		adj[p].push_back({i, c});
	}
	for (int i = 2; i <= n; i++) {
		if (adj[i].empty()) {
			assert(i >= n - m + 1);
		}
	}
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j < N; j++) {
			for (auto [nxt, w] : adj[i]) {
				ll mn = 1e18;
				for (int k = 0; k <= j; k++) {
					mn = min(mn, dp[i][j - k] + abs(k - w));
				}
				dp[i][j] += mn;
				dp[i][j] = min(dp[i][j], inf);
			}
		}
	}
	cout << *min_element(dp[1], dp[1] + N) << '\n';
	return 0;
}

# 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 2 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 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -