답안 #960150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960150 2024-04-09T18:25:05 Z MinaRagy06 Fireworks (APIO16_fireworks) C++17
19 / 100
19 ms 1116 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 = n; i >= 1; i--) {
		for (int j = 0; j < N; j++) {
			if (adj[i].empty() && j) dp[i][j] = inf;
			for (auto [nxt, w] : adj[i]) {
				ll mn = 1e18;
				for (int k = 0; k <= j; k++) {
					mn = min(mn, dp[nxt][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;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 4 ms 592 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 6 ms 604 KB Output is correct
6 Correct 7 ms 604 KB Output is correct
7 Correct 8 ms 844 KB Output is correct
8 Correct 9 ms 860 KB Output is correct
9 Correct 10 ms 860 KB Output is correct
10 Correct 11 ms 860 KB Output is correct
11 Correct 12 ms 992 KB Output is correct
12 Correct 14 ms 860 KB Output is correct
13 Correct 15 ms 1100 KB Output is correct
14 Correct 15 ms 1116 KB Output is correct
15 Correct 15 ms 1116 KB Output is correct
16 Correct 15 ms 1112 KB Output is correct
17 Correct 15 ms 1116 KB Output is correct
18 Correct 19 ms 1112 KB Output is correct
19 Correct 16 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -