Submission #42620

#TimeUsernameProblemLanguageResultExecution timeMemory
42620repeatingFireworks (APIO16_fireworks)C++11
7 / 100
8 ms7732 KiB
#include <bits/stdc++.h> #define F first #define S second #define P push #define pb push_back #define MEM(dp,i) memset(dp,i,sizeof(dp)) #define W while #define R return #define C continue #define SI size() #define ll long long #define ld long double #define pll pair<ll,ll> #define pii pair<int,int> #define SF(x) scanf("%Id",&x) #define SF2(x,y) scanf("%Id%Id",&x,&y) #define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z) #define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o) #define all(v) v.begin(),v.end() using namespace std; const long long INF = 1e9+1; const long long MOD = 1e9+7; const int MX=300015; vector<pll> adj[MX]; ll a[MX]; int n,m; void dfs(int ver,ll val){ for(auto i : adj[ver]){ dfs(i.F,val+i.S); } if(ver>n)a[ver]=val; } ll res; pll seg(vector<pll> &v){ sort(all(v)); ll sum=0,l=0,r=0; ll mn=INF*INF; ll rl=INF*INF,rr=0; for(auto i : v){ if(i.S==1) sum+=i.F-v[0].F,r++; } r--; mn=sum; rl=v[0].F,rr=v[0].F; for(int i=1;i<v.size();i++){ sum-=1LL*r*(v[i].F-v[i-1].F); sum+=1LL*l*(v[i].F-v[i-1].F); if(v[i].S==1)r--; else l++; if(mn==sum){ mn=sum; rl=min(rl,v[i].F); rr=max(rr,v[i].F); } if(mn>sum){ mn=sum; rr=v[i].F; rl=v[i].F; } } res+=mn; R{rl,rr}; } pll pro(int ver){ if(ver>n){ R {a[ver],a[ver]}; } pll ret; vector<pll> v; pll p; for(auto i : adj[ver]){ p=pro(i.F); v.pb({p.F,1}); v.pb({p.S,2}); } ret=seg(v); // cout<<ver<<" "<<res<<endl; R ret; } int main(){ cin>>n>>m; for(int i=2;i<=n+m;i++){ int x,y; scanf("%d%d",&x,&y); adj[x].pb({i,y}); } dfs(1,0); pro(1); cout<<res; }

Compilation message (stderr)

fireworks.cpp: In function 'std::pair<long long int, long long int> seg(std::vector<std::pair<long long int, long long int> >&)':
fireworks.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<v.size();i++){
                  ^
fireworks.cpp: In function 'int main()':
fireworks.cpp:87:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         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...