Submission #113398

# Submission time Handle Problem Language Result Execution time Memory
113398 2019-05-25T09:55:28 Z 임유진(#2858) Fireworks (APIO16_fireworks) C++14
26 / 100
32 ms 1152 KB
#include<stdio.h>
#include<algorithm>
#include<vector>

using namespace std;

#define LINF 300000000000ll

int P[301], C[301];
vector<int> e[301];
long long dp[301][301];

long long gabs(long long x){
	return x>0?x:-x;
}

void gdp(int x){
	if(e[x].empty()){
		for(int i=0; i<=300; i++) dp[x][i]=gabs(C[x]-i);
		return;
	}
	for(auto a:e[x]) gdp(a);
	for(int i=0; i<=300; i++){
		dp[x][i]=LINF;
		for(int j=0; j<=i; j++){
			long long t=gabs(C[x]-j);
			for(auto a:e[x]) t+=dp[a][i-j];
			if(t<dp[x][i]) dp[x][i]=t;
		}
	}
}

int main(){
	int N, M;
	long long ans=0;

	scanf("%d%d", &N, &M);
	if(N==1){
		for(int i=0; i<M; i++) scanf("%d%d", P+i, C+i);
	
		sort(C, C+M);
		for(int i=0; i<M/2; i++) ans+=C[M/2]-C[i];
		for(int i=M/2+1; i<M; i++) ans+=C[i]-C[M/2];
	}
	else{
		for(int i=2; i<=N+M; i++) scanf("%d%d", P+i, C+i);
		for(int i=2; i<=N+M; i++) e[P[i]].push_back(i);
		gdp(1);	
		ans=LINF;
		for(int i=0; i<=300; i++) if(dp[1][i]<ans) ans=dp[1][i];

		/*
		for(int i=1; i<=N+M; i++){
			for(int j=0; j<=17; j++) printf("%2lld ", dp[i][j]);
			printf("\n");
		}
		*/
	}

	printf("%lld", ans);
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:39:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i=0; i<M; i++) scanf("%d%d", P+i, C+i);
                          ~~~~~^~~~~~~~~~~~~~~~~~
fireworks.cpp:46:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i=2; i<=N+M; i++) scanf("%d%d", P+i, C+i);
                             ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 10 ms 640 KB Output is correct
6 Correct 11 ms 640 KB Output is correct
7 Correct 12 ms 768 KB Output is correct
8 Correct 14 ms 768 KB Output is correct
9 Correct 15 ms 768 KB Output is correct
10 Correct 16 ms 768 KB Output is correct
11 Correct 17 ms 896 KB Output is correct
12 Correct 19 ms 980 KB Output is correct
13 Correct 21 ms 1024 KB Output is correct
14 Correct 32 ms 1016 KB Output is correct
15 Correct 23 ms 1024 KB Output is correct
16 Correct 22 ms 1152 KB Output is correct
17 Correct 22 ms 1040 KB Output is correct
18 Correct 22 ms 1024 KB Output is correct
19 Correct 21 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 11 ms 512 KB Output is correct
15 Correct 10 ms 640 KB Output is correct
16 Correct 11 ms 640 KB Output is correct
17 Correct 12 ms 768 KB Output is correct
18 Correct 14 ms 768 KB Output is correct
19 Correct 15 ms 768 KB Output is correct
20 Correct 16 ms 768 KB Output is correct
21 Correct 17 ms 896 KB Output is correct
22 Correct 19 ms 980 KB Output is correct
23 Correct 21 ms 1024 KB Output is correct
24 Correct 32 ms 1016 KB Output is correct
25 Correct 23 ms 1024 KB Output is correct
26 Correct 22 ms 1152 KB Output is correct
27 Correct 22 ms 1040 KB Output is correct
28 Correct 22 ms 1024 KB Output is correct
29 Correct 21 ms 996 KB Output is correct
30 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 11 ms 512 KB Output is correct
15 Correct 10 ms 640 KB Output is correct
16 Correct 11 ms 640 KB Output is correct
17 Correct 12 ms 768 KB Output is correct
18 Correct 14 ms 768 KB Output is correct
19 Correct 15 ms 768 KB Output is correct
20 Correct 16 ms 768 KB Output is correct
21 Correct 17 ms 896 KB Output is correct
22 Correct 19 ms 980 KB Output is correct
23 Correct 21 ms 1024 KB Output is correct
24 Correct 32 ms 1016 KB Output is correct
25 Correct 23 ms 1024 KB Output is correct
26 Correct 22 ms 1152 KB Output is correct
27 Correct 22 ms 1040 KB Output is correct
28 Correct 22 ms 1024 KB Output is correct
29 Correct 21 ms 996 KB Output is correct
30 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Halted 0 ms 0 KB -