답안 #409659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409659 2021-05-21T09:47:40 Z Kerim Fireworks (APIO16_fireworks) C++17
26 / 100
17 ms 1044 KB
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=303;
int dp[N][N],p[N],c[N];
int main(){
    //freopen("file.in", "r", stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=2;i<=n+m;i++)
		scanf("%d%d",p+i,c+i);
	if(n==1){
		vector<int>v;
		for(int i=2;i<=m+1;i++)v.pb(c[i]);
		sort(all(v));
		ll ans=ll(1e16);
		for(int i=0;i<int(v.size());i++){
			ll sum=0;
			for(int j=0;j<int(v.size());j++)
				sum+=abs(v[i]-v[j]);
			umin(ans,sum);
		}
		printf("%lld\n",ans);
	}
	else{
	    for(int i=n+m;i>=1;i--){
	    	if(i>n){
		    	for(int j=0;j<N;j++)
		    		dp[p[i]][j]+=abs(j-c[i]);
	    	}
	    	else{
		    	for(int j=0;j<N;j++){
		    		int cost=INF;
					for(int k=0;k<=j;k++)
						umin(cost,dp[i][k]+abs(k+c[i]-j));	
		    		dp[p[i]][j]+=cost;
				}
			}
	    }
	    int ans=INF;
	    for(int i=0;i<N;i++)
			umin(ans,dp[1][i]);
	    printf("%d\n",ans);
	}
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
fireworks.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d%d",p+i,c+i);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 6 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 5 ms 332 KB Output is correct
7 Correct 5 ms 332 KB Output is correct
8 Correct 5 ms 332 KB Output is correct
9 Correct 6 ms 332 KB Output is correct
10 Correct 6 ms 332 KB Output is correct
11 Correct 7 ms 332 KB Output is correct
12 Correct 7 ms 332 KB Output is correct
13 Correct 8 ms 460 KB Output is correct
14 Correct 17 ms 548 KB Output is correct
15 Correct 9 ms 460 KB Output is correct
16 Correct 8 ms 332 KB Output is correct
17 Correct 9 ms 460 KB Output is correct
18 Correct 9 ms 468 KB Output is correct
19 Correct 8 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 6 ms 332 KB Output is correct
15 Correct 4 ms 332 KB Output is correct
16 Correct 5 ms 332 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 5 ms 332 KB Output is correct
19 Correct 6 ms 332 KB Output is correct
20 Correct 6 ms 332 KB Output is correct
21 Correct 7 ms 332 KB Output is correct
22 Correct 7 ms 332 KB Output is correct
23 Correct 8 ms 460 KB Output is correct
24 Correct 17 ms 548 KB Output is correct
25 Correct 9 ms 460 KB Output is correct
26 Correct 8 ms 332 KB Output is correct
27 Correct 9 ms 460 KB Output is correct
28 Correct 9 ms 468 KB Output is correct
29 Correct 8 ms 444 KB Output is correct
30 Runtime error 10 ms 1044 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 6 ms 332 KB Output is correct
15 Correct 4 ms 332 KB Output is correct
16 Correct 5 ms 332 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 5 ms 332 KB Output is correct
19 Correct 6 ms 332 KB Output is correct
20 Correct 6 ms 332 KB Output is correct
21 Correct 7 ms 332 KB Output is correct
22 Correct 7 ms 332 KB Output is correct
23 Correct 8 ms 460 KB Output is correct
24 Correct 17 ms 548 KB Output is correct
25 Correct 9 ms 460 KB Output is correct
26 Correct 8 ms 332 KB Output is correct
27 Correct 9 ms 460 KB Output is correct
28 Correct 9 ms 468 KB Output is correct
29 Correct 8 ms 444 KB Output is correct
30 Runtime error 10 ms 1044 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -