# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
21841 | 2017-04-26T10:20:51 Z | mohammad_kilani | Fireworks (APIO16_fireworks) | C++14 | 79 ms | 2396 KB |
#include<bits/stdc++.h> using namespace std; int n,m; vector<vector<pair<int,int> > > g; int dp[310][310]; int calc(int i,int j){ if(dp[i][j] == -1){ int si = g[i].size(); dp[i][j] = 0 ; for(int k=0;k<si;k++){ int node = g[i][k].first ; int cost = 1e9; if(node > n){ int dis = j - g[i][k].second; if(dis < 0) dis*=-1; cost = dis ; } else { for(int l=0;l<=j;l++){ int dis = (j - l) - g[i][k].second; if(dis < 0) dis*=-1; cost = min(cost,dis+calc(node,l)); } } dp[i][j] +=cost; } } return dp[i][j]; } int main(){ //freopen("in.in","r",stdin); memset(dp,-1,sizeof(dp)); scanf("%d%d",&n,&m); g.resize(n+m+10); for(int i=2;i<=n+m;i++){ int p,c; scanf("%d%d",&p,&c); g[p].push_back(make_pair(i,c)); } int ans = 1e9; for(int i =0;i<305;i++){ ans = min(ans,calc(1,i)); } cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 3 ms | 2396 KB | Output is correct |
3 | Correct | 3 ms | 2396 KB | Output is correct |
4 | Correct | 23 ms | 2396 KB | Output is correct |
5 | Correct | 13 ms | 2396 KB | Output is correct |
6 | Correct | 16 ms | 2396 KB | Output is correct |
7 | Correct | 16 ms | 2396 KB | Output is correct |
8 | Correct | 19 ms | 2396 KB | Output is correct |
9 | Correct | 23 ms | 2396 KB | Output is correct |
10 | Correct | 26 ms | 2396 KB | Output is correct |
11 | Correct | 29 ms | 2396 KB | Output is correct |
12 | Correct | 33 ms | 2396 KB | Output is correct |
13 | Correct | 36 ms | 2396 KB | Output is correct |
14 | Correct | 79 ms | 2396 KB | Output is correct |
15 | Correct | 43 ms | 2396 KB | Output is correct |
16 | Correct | 36 ms | 2396 KB | Output is correct |
17 | Correct | 36 ms | 2396 KB | Output is correct |
18 | Correct | 36 ms | 2396 KB | Output is correct |
19 | Correct | 33 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |