Submission #409646

# Submission time Handle Problem Language Result Execution time Memory
409646 2021-05-21T09:22:48 Z juggernaut Fireworks (APIO16_fireworks) C++17
19 / 100
22 ms 7704 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
vector<pair<int,int>>g[300005];
int dp[305][305],n,m;
void dfs(int v){
    if(v>n){
        dp[v][0]=0;
        for(int i=1;i<=300;i++)dp[v][i]=1e9;
        return;
    }
    for(auto &[to,w]:g[v]){
        dfs(to);
        for(int i=0;i<=300;i++){
            int mn=1e7;
            for(int j=0;j<=i;j++)umin(mn,dp[to][j]+abs(i-j-w));
            dp[v][i]+=mn;
        }
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=2;i<=n+m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        g[x].emplace_back(i,y);
    }
    dfs(1);
    int ans=2e9;
    for(int i=0;i<=300;i++)umin(ans,dp[1][i]);
    printf("%d",ans);
}

Compilation message

fireworks.cpp: In function 'void usaco(std::string)':
fireworks.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fireworks.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
fireworks.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 8 ms 7372 KB Output is correct
4 Correct 10 ms 7372 KB Output is correct
5 Correct 12 ms 7456 KB Output is correct
6 Correct 13 ms 7500 KB Output is correct
7 Correct 14 ms 7500 KB Output is correct
8 Correct 15 ms 7500 KB Output is correct
9 Correct 15 ms 7500 KB Output is correct
10 Correct 20 ms 7500 KB Output is correct
11 Correct 21 ms 7600 KB Output is correct
12 Correct 20 ms 7628 KB Output is correct
13 Correct 20 ms 7660 KB Output is correct
14 Correct 22 ms 7620 KB Output is correct
15 Correct 22 ms 7628 KB Output is correct
16 Correct 22 ms 7596 KB Output is correct
17 Correct 22 ms 7696 KB Output is correct
18 Correct 22 ms 7692 KB Output is correct
19 Correct 22 ms 7704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -