Submission #400508

# Submission time Handle Problem Language Result Execution time Memory
400508 2021-05-08T08:26:51 Z Hazem Fireworks (APIO16_fireworks) C++14
19 / 100
31 ms 5836 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 2e5+10;
const int M = 2e3+10;
const LL INF = 1e9;
const LL LINF = 1e14;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;

vector<pair<int,LL>>adj[N];
LL dp[N][350];

void dfs(int i){

    if(adj[i].empty()){
        for(int j=1;j<=300;j++)
            dp[i][j] = LINF;
    }

    for(auto x:adj[i]){
        
        dfs(x.F);

        for(int j=0;j<=300;j++){
     
            LL mn = LINF;
            for(int k=0;k<=j;k++)
                mn = min(mn,dp[x.F][k]+abs(x.S-(abs(k-j))));

            dp[i][j] += mn;
        }
    }
}

int main(){

    //freopen("out.txt","w",stdout);

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

    for(int i=2;i<=n+m;i++){
        LL v,w;
        scanf("%lld%lld",&v,&w);
        adj[v].push_back({i,w});
    }

    dfs(1);

    LL ans = LINF;
    for(int i=0;i<=300;i++)
        ans = min(ans,dp[1][i]);

    printf("%lld\n",ans);
}   

//

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
fireworks.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%lld%lld",&v,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5016 KB Output is correct
2 Correct 7 ms 5068 KB Output is correct
3 Correct 9 ms 5140 KB Output is correct
4 Correct 12 ms 5196 KB Output is correct
5 Correct 14 ms 5324 KB Output is correct
6 Correct 15 ms 5336 KB Output is correct
7 Correct 18 ms 5340 KB Output is correct
8 Correct 19 ms 5452 KB Output is correct
9 Correct 21 ms 5520 KB Output is correct
10 Correct 23 ms 5596 KB Output is correct
11 Correct 24 ms 5584 KB Output is correct
12 Correct 28 ms 5688 KB Output is correct
13 Correct 29 ms 5696 KB Output is correct
14 Correct 29 ms 5764 KB Output is correct
15 Correct 30 ms 5836 KB Output is correct
16 Correct 31 ms 5784 KB Output is correct
17 Correct 30 ms 5792 KB Output is correct
18 Correct 31 ms 5744 KB Output is correct
19 Correct 31 ms 5788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -