Submission #400680

# Submission time Handle Problem Language Result Execution time Memory
400680 2021-05-08T13:51:28 Z A_D Fireworks (APIO16_fireworks) C++14
19 / 100
21 ms 1016 KB
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=301;
int a[N];
int dp[N][N];
vector<ii> g[N];
void dfs(int u)
{
    for(auto x:g[u]){
        dfs(x.F);
        for(int j=0;j<=300;j++){
            int mn=1e18;
            for(int k=0;k<=j;k++){
                mn=min(mn,dp[x.F][k]+abs(j-(x.S+k)));
            }
            dp[u][j]+=mn;
        }
    }
}
void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=2;i<=n+m;i++){
        int u,c;
        scanf("%lld",&u);
        scanf("%lld",&c);
        g[u].push_back({i,c});
        if(i>n){
            for(int j=1;j<=300;j++){
                dp[i][j]=1e13;
            }
        }
    }
    dfs(1);
    /*
    cout<<endl;
    for(int i=1;i<=n+m;i++){
        for(int j=1;j<=10;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
    */
    int mn=1e18;
    for(int i=0;i<=300;i++)mn=min(mn,dp[1][i]);
    cout<<mn<<endl;
}
main()
{
    int t=1;
//    cin>>t;
    while(t--)solve();
}

Compilation message

fireworks.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main()
      |      ^
fireworks.cpp: In function 'void solve()':
fireworks.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |         scanf("%lld",&u);
      |         ~~~~~^~~~~~~~~~~
fireworks.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |         scanf("%lld",&c);
      |         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 4 ms 444 KB Output is correct
4 Correct 6 ms 496 KB Output is correct
5 Correct 7 ms 588 KB Output is correct
6 Correct 8 ms 564 KB Output is correct
7 Correct 10 ms 588 KB Output is correct
8 Correct 11 ms 716 KB Output is correct
9 Correct 12 ms 720 KB Output is correct
10 Correct 13 ms 732 KB Output is correct
11 Correct 15 ms 872 KB Output is correct
12 Correct 16 ms 908 KB Output is correct
13 Correct 17 ms 960 KB Output is correct
14 Correct 18 ms 956 KB Output is correct
15 Correct 20 ms 972 KB Output is correct
16 Correct 18 ms 1016 KB Output is correct
17 Correct 18 ms 920 KB Output is correct
18 Correct 21 ms 992 KB Output is correct
19 Correct 18 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -