답안 #227231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
227231 2020-04-26T14:52:01 Z theStaticMind Fireworks (APIO16_fireworks) C++14
19 / 100
38 ms 8184 KB
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int n, m;
vector<ii> adj[300005];
int g[300005][305];

void dfs(int x, int c, int d){
	for(int i = 1; i <= 300; i++) g[x][i] = 0;
	if(x > n)
	for(int i = 1; i <= 300; i++){
		if(i == d) g[x][i] = 0;
		else g[x][i] = INF;
	}
	for(auto p : adj[x]){
		dfs(p.first, p.second, d + p.second);
		for(int a = 1; a <= 300; a++){
			g[x][a] += g[p.first][a];
		}
	}
	vector<int> f(305, INF);
	for(int j = 1; j <= 300; j++){
		for(int k = 1; k <= j + c && k <= 300; k++){
			f[j] = min(f[j], g[x][k] + abs(k - j));
		}
	}

	for(int i = 1; i <= 300; i++) g[x][i] = f[i];

}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;
	for(int i = 2; i <= n + m; i++){
		int x, c;
		cin >> x >> c;
		adj[x].pb({i, c});
	}

	dfs(1, 0, 0);

	int ans = INF;
	for(int i = 1; i <= 300; i++) ans = min(ans, g[1][i]);

	cout << ans;

}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7424 KB Output is correct
2 Correct 14 ms 7424 KB Output is correct
3 Correct 14 ms 7680 KB Output is correct
4 Correct 17 ms 7680 KB Output is correct
5 Correct 21 ms 7680 KB Output is correct
6 Correct 20 ms 7680 KB Output is correct
7 Correct 22 ms 7936 KB Output is correct
8 Correct 24 ms 7808 KB Output is correct
9 Correct 25 ms 7808 KB Output is correct
10 Correct 26 ms 7936 KB Output is correct
11 Correct 30 ms 8064 KB Output is correct
12 Correct 31 ms 8056 KB Output is correct
13 Correct 33 ms 8064 KB Output is correct
14 Correct 30 ms 8064 KB Output is correct
15 Correct 38 ms 8064 KB Output is correct
16 Correct 34 ms 8184 KB Output is correct
17 Correct 34 ms 8064 KB Output is correct
18 Correct 35 ms 8064 KB Output is correct
19 Correct 34 ms 8064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -