Submission #409646

#TimeUsernameProblemLanguageResultExecution timeMemory
409646juggernautFireworks (APIO16_fireworks)C++17
19 / 100
22 ms7704 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...