Submission #554315

# Submission time Handle Problem Language Result Execution time Memory
554315 2022-04-28T06:47:42 Z Keshi Fireworks (APIO16_fireworks) C++17
19 / 100
7 ms 1504 KB
//In the name of God
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int maxn = 512;
const ll mod = 1e9 + 7;
const ll inf = 1e15;
 
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
 
ll pw(ll a, ll b){
	ll c = 1;
	while(b){
		if(b & 1) c = c * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return c;
}
 
int n, m, p[maxn], c[maxn];
vector<int> g[maxn];
ll dp[maxn][maxn];
 
void dfs(int v){
	for(int u : g[v]){
		dfs(u);
		for(int i = c[v]; i < maxn; i++){
			dp[v][i] += dp[u][i - c[v]];
		}
	}
	if(g[v].empty()){
      	assert(v > n);
		fill(dp[v], dp[v] + maxn, inf);
		dp[v][c[v]] = 0;
	}
  	if(v == 1) return;
	for(int i = 0; i < c[v]; i++){
		dp[v][i] = inf;
	}
	ll mn = inf;
	for(int i = 0; i < maxn; i++){
		dp[v][i] = min(dp[v][i], i + mn);
		mn = min(mn, dp[v][i] - i);
	}
	for(int i = 0; i < maxn; i++){
		for(int j = 0; j <= c[v]; j++){
         	if(i + j >= maxn) break;
          	dp[v][i] = min(dp[v][i], dp[v][i + j] + j);
        }
	}
	return;
}
 
int main(){
	fast_io;
 
	cin >> n >> m;
	for(int i = 2; i <= n + m; i++){
		cin >> p[i] >> c[i];
     	assert(i <= n || p[i] <= n);
		g[p[i]].pb(i);
	}
	dfs(1);
	ll ans = inf;
	for(int i = 0; i < maxn; i++){
		ans = min(ans, dp[1][i]);
	}
	cout << ans << "\n";
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 1 ms 728 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 5 ms 980 KB Output is correct
9 Correct 4 ms 1112 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 7 ms 1364 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 7 ms 1364 KB Output is correct
14 Correct 2 ms 1504 KB Output is correct
15 Correct 6 ms 1500 KB Output is correct
16 Correct 5 ms 1496 KB Output is correct
17 Correct 6 ms 1492 KB Output is correct
18 Correct 6 ms 1492 KB Output is correct
19 Correct 6 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -