Submission #49908

# Submission time Handle Problem Language Result Execution time Memory
49908 2018-06-04T20:30:10 Z hamzqq9 Fireworks (APIO16_fireworks) C++14
26 / 100
35 ms 1480 KB
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define cc pair<char,char>
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 100000000000000000
#define M 10000002
#define N 305
#define LOG 20
#define magic 100
#define KOK 250
#define EPS 0.0025
#define pw(x) ((1ll)<<(x))
#define PI 3.1415926535
using namespace std;

int n,m,x,y;
ll ans,dp[N][N],sum[N];
vector<ii> v[N];

void dfs(int node,int ue) {

	for(ii i:v[node]) dfs(i.st,i.nd);

	memset(sum,0,sizeof(sum));

	if(node>n) {

		for(int i=1;i<N;i++) sum[i]=inf;

	}
	else {
	
		for(ii i:v[node]) {

			for(int cst=0;cst<N;cst++) sum[cst]+=dp[i.st][cst];

		}
	
	}

	for(int i=0;i<N;i++) {

		if(node==1) {

			dp[node][i]=sum[i];

			continue ;

		}

		dp[node][i]=inf;

		for(int j=0;j<=i;j++) {

			umin(dp[node][i],sum[j]+abs(ue-(i-j)));

		}

	}

}

int main() {
 
 	#if 0
	freopen("input.txt","r",stdin);
 	#endif

	scanf("%d %d",&n,&m);

	for(int i=2;i<=n+m;i++) {

		scanf("%d %d",&x,&y);

		v[x].pb({i,y});

	}

	if(n==1) {

		vector<int> c;

		for(ii go:v[1]) c.pb(go.nd);

		sort(all(c));

	    ll res=0;

		for(int i=0;i<sz(c);i++) res+=abs(c[i]-c[sz(c)/2]);

		printf("%lld",res);

		return 0;

	}

	dfs(1,0);

	ans=inf;

	for(int i=0;i<N;i++) umin(ans,dp[1][i]);

	printf("%lld",ans);

}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:96: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:100:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
6 Correct 2 ms 428 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 6 ms 828 KB Output is correct
4 Correct 9 ms 828 KB Output is correct
5 Correct 10 ms 828 KB Output is correct
6 Correct 11 ms 912 KB Output is correct
7 Correct 13 ms 972 KB Output is correct
8 Correct 14 ms 1100 KB Output is correct
9 Correct 18 ms 1104 KB Output is correct
10 Correct 17 ms 1112 KB Output is correct
11 Correct 35 ms 1264 KB Output is correct
12 Correct 20 ms 1264 KB Output is correct
13 Correct 23 ms 1312 KB Output is correct
14 Correct 27 ms 1332 KB Output is correct
15 Correct 23 ms 1336 KB Output is correct
16 Correct 23 ms 1340 KB Output is correct
17 Correct 23 ms 1380 KB Output is correct
18 Correct 23 ms 1380 KB Output is correct
19 Correct 23 ms 1480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
6 Correct 2 ms 428 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 828 KB Output is correct
14 Correct 9 ms 828 KB Output is correct
15 Correct 10 ms 828 KB Output is correct
16 Correct 11 ms 912 KB Output is correct
17 Correct 13 ms 972 KB Output is correct
18 Correct 14 ms 1100 KB Output is correct
19 Correct 18 ms 1104 KB Output is correct
20 Correct 17 ms 1112 KB Output is correct
21 Correct 35 ms 1264 KB Output is correct
22 Correct 20 ms 1264 KB Output is correct
23 Correct 23 ms 1312 KB Output is correct
24 Correct 27 ms 1332 KB Output is correct
25 Correct 23 ms 1336 KB Output is correct
26 Correct 23 ms 1340 KB Output is correct
27 Correct 23 ms 1380 KB Output is correct
28 Correct 23 ms 1380 KB Output is correct
29 Correct 23 ms 1480 KB Output is correct
30 Runtime error 2 ms 1480 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 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
6 Correct 2 ms 428 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 828 KB Output is correct
14 Correct 9 ms 828 KB Output is correct
15 Correct 10 ms 828 KB Output is correct
16 Correct 11 ms 912 KB Output is correct
17 Correct 13 ms 972 KB Output is correct
18 Correct 14 ms 1100 KB Output is correct
19 Correct 18 ms 1104 KB Output is correct
20 Correct 17 ms 1112 KB Output is correct
21 Correct 35 ms 1264 KB Output is correct
22 Correct 20 ms 1264 KB Output is correct
23 Correct 23 ms 1312 KB Output is correct
24 Correct 27 ms 1332 KB Output is correct
25 Correct 23 ms 1336 KB Output is correct
26 Correct 23 ms 1340 KB Output is correct
27 Correct 23 ms 1380 KB Output is correct
28 Correct 23 ms 1380 KB Output is correct
29 Correct 23 ms 1480 KB Output is correct
30 Runtime error 2 ms 1480 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Halted 0 ms 0 KB -