Submission #959925

# Submission time Handle Problem Language Result Execution time Memory
959925 2024-04-09T10:21:04 Z Trisanu_Das Fireworks (APIO16_fireworks) C++17
19 / 100
20 ms 1184 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 300 + 10;
const ll inf = 1e18;
 
vector<pair<int,int>> t[maxn];
ll dp[maxn][maxn];
int lo[maxn], r[maxn];
 
void dfs(int v){
	if (t[v].empty()){
		dp[v][0] = 0;
		for (int j = 1; j < maxn; j++)
			dp[v][j] = inf;
		return;
	}
	for (auto [u,c] : t[v]){
		dfs(u);
		for (int i = 0; i < maxn; i++){
			ll now = inf;
			for (int j = 0; j <= i; j++)
				now = min(now, dp[u][j] + abs(i-j-c));
			dp[v][i] += now;
		}
	}
}
 
int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 2; i <= n+m; i++){
		int v, c;
		cin >> v >> c;
		t[v].push_back({i,c});
	}
	dfs(1);
	ll answer = inf;
	for (int i = 0; i < maxn; i++)
		answer = min(answer, dp[1][i]);
	cout << answer << endl;
}
# 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 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 6 ms 728 KB Output is correct
6 Correct 7 ms 604 KB Output is correct
7 Correct 8 ms 764 KB Output is correct
8 Correct 9 ms 908 KB Output is correct
9 Correct 11 ms 860 KB Output is correct
10 Correct 12 ms 980 KB Output is correct
11 Correct 14 ms 860 KB Output is correct
12 Correct 13 ms 860 KB Output is correct
13 Correct 14 ms 1116 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 1116 KB Output is correct
17 Correct 15 ms 1116 KB Output is correct
18 Correct 15 ms 1064 KB Output is correct
19 Correct 20 ms 1184 KB Output is correct
# 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 -