Submission #21843

# Submission time Handle Problem Language Result Execution time Memory
21843 2017-04-26T10:27:32 Z mohammad_kilani Fireworks (APIO16_fireworks) C++14
26 / 100
83 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));
    }
    if(n == 1){
        int si = g[1].size();
        long long ans = 1e16;
        for(int i=0;i<si;i++){
                int num = g[1][i].second;
                long long all = 0 ;
            for(int j=0;j<si;j++){
                int cur = g[1][j].second - num;
                if(cur < 0)
                    cur*=-1;
                all+=(long long)cur;
            }
            ans = min(ans,all);
        }
        cout << ans << endl;
        return 0;
    }
    int ans = 1e9;
    for(int i =0;i<305;i++){
        ans = min(ans,calc(1,i));
    }
    cout << ans << endl;
   return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:41:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
fireworks.cpp:45:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&p,&c);
                                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory 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 33 ms 2396 KB Output is correct
14 Correct 79 ms 2396 KB Output is correct
15 Correct 36 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 39 ms 2396 KB Output is correct
19 Correct 33 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 23 ms 2396 KB Output is correct
15 Correct 13 ms 2396 KB Output is correct
16 Correct 16 ms 2396 KB Output is correct
17 Correct 16 ms 2396 KB Output is correct
18 Correct 19 ms 2396 KB Output is correct
19 Correct 23 ms 2396 KB Output is correct
20 Correct 26 ms 2396 KB Output is correct
21 Correct 29 ms 2396 KB Output is correct
22 Correct 33 ms 2396 KB Output is correct
23 Correct 33 ms 2396 KB Output is correct
24 Correct 79 ms 2396 KB Output is correct
25 Correct 36 ms 2396 KB Output is correct
26 Correct 36 ms 2396 KB Output is correct
27 Correct 36 ms 2396 KB Output is correct
28 Correct 39 ms 2396 KB Output is correct
29 Correct 33 ms 2396 KB Output is correct
30 Incorrect 83 ms 2396 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 23 ms 2396 KB Output is correct
15 Correct 13 ms 2396 KB Output is correct
16 Correct 16 ms 2396 KB Output is correct
17 Correct 16 ms 2396 KB Output is correct
18 Correct 19 ms 2396 KB Output is correct
19 Correct 23 ms 2396 KB Output is correct
20 Correct 26 ms 2396 KB Output is correct
21 Correct 29 ms 2396 KB Output is correct
22 Correct 33 ms 2396 KB Output is correct
23 Correct 33 ms 2396 KB Output is correct
24 Correct 79 ms 2396 KB Output is correct
25 Correct 36 ms 2396 KB Output is correct
26 Correct 36 ms 2396 KB Output is correct
27 Correct 36 ms 2396 KB Output is correct
28 Correct 39 ms 2396 KB Output is correct
29 Correct 33 ms 2396 KB Output is correct
30 Incorrect 83 ms 2396 KB Output isn't correct
31 Halted 0 ms 0 KB -