Submission #793182

# Submission time Handle Problem Language Result Execution time Memory
793182 2023-07-25T15:22:01 Z ToniB Fireworks (APIO16_fireworks) C++17
19 / 100
99 ms 1548 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 505;

int n, m, L[MAXN], R[MAXN];
vector<pair<int, int> > adj[MAXN];
ll walk[MAXN], dp[MAXN][MAXN];

void precalc(int node){
	for(pair<int, int> x : adj[node]){
		walk[x.first] = walk[node] + x.second;
		precalc(x.first);
	}
}

void dfs(int node){
	if(node >= n){
		for(int i = 0; i < MAXN; ++i) dp[node][i] = 1e9;
		dp[node][walk[node]] = 0;
	}
	for(pair<int, int> x : adj[node]){
		dfs(x.first);
		for(int i = 0; i < MAXN; ++i){
			ll mini = 1e9;
			for(int j = 0; j < MAXN; ++j){
				if(x.second + i - j >= 0) mini = min(mini, dp[x.first][j] + abs(i - j));
			}
			dp[node][i] += mini;
		}
	}
}

int main(){
	cin >> n >> m;
	for(int i = 1; i < n + m; ++i){
		int p, c;
		cin >> p >> c, --p;
		adj[p].push_back({i, c});
	}
	precalc(0);
	dfs(0);
	ll ans = 1e9;
	for(int i = 0; i < MAXN; ++i) ans = min(ans, dp[0][i]);
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 452 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 10 ms 468 KB Output is correct
3 Correct 16 ms 560 KB Output is correct
4 Correct 23 ms 692 KB Output is correct
5 Correct 32 ms 724 KB Output is correct
6 Correct 34 ms 748 KB Output is correct
7 Correct 38 ms 924 KB Output is correct
8 Correct 54 ms 1024 KB Output is correct
9 Correct 73 ms 1048 KB Output is correct
10 Correct 70 ms 1148 KB Output is correct
11 Correct 65 ms 1128 KB Output is correct
12 Correct 68 ms 1312 KB Output is correct
13 Correct 67 ms 1356 KB Output is correct
14 Correct 72 ms 1484 KB Output is correct
15 Correct 85 ms 1548 KB Output is correct
16 Correct 79 ms 1392 KB Output is correct
17 Correct 99 ms 1444 KB Output is correct
18 Correct 76 ms 1484 KB Output is correct
19 Correct 80 ms 1380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 452 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 452 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -