Submission #924685

#TimeUsernameProblemLanguageResultExecution timeMemory
924685DzadzoWiring (IOI17_wiring)C++14
100 / 100
44 ms8896 KiB
#include <bits/stdc++.h> #include "wiring.h" #define ll long long #define pb push_back #define S second #define F first #define pii pair<int,int> #define vi vector <ll> #define vvi vector <vi> #define vvvi vector <vvi> #define vp vector <pii> #define vvp vector <vp> #define vb vector <bool> #define vvb vector <vb>; #define INF LLONG_MAX #define MOD 1000000007 #define MAXN 100000 using namespace std; ll min_total_length(std::vector<int> r, std::vector<int> b){ vp v; v.pb({0,0}); for (auto x:r)v.pb(make_pair(x*1ll,-1*1ll)); for (auto x:b)v.pb(make_pair(x*1ll,1ll)); int n=v.size()-1; sort(v.begin()+1,v.end()); vi dp(n+1,INF),p(n+1); dp[0]=0; for (int i=1;i<=n;i++){ p[i]=p[i-1]+v[i].F; } int cur=1,prev=0; while (v[prev].S==v[prev+1].S)cur++; int ind; for (int i=cur+1;i<=n;i++){ if (v[i].S!=v[i-1].S){ ind=v[i-1].F; for (int j=i-cur;j<i;j++)if (dp[j-1]!=INF)dp[j]=min(dp[j],dp[j-1]+v[i].F-v[j].F); prev=cur; cur=0; } cur++; if (dp[i-1]!=INF) dp[i]=min(dp[i],dp[i-1]+v[i].F-ind); if (cur<=prev && dp[i-2*cur]!=INF)dp[i]=min(dp[i],dp[i-2*cur]+p[i]+p[i-2*cur]-2*p[i-cur]); } return dp[n]; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:43:34: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |   dp[i]=min(dp[i],dp[i-1]+v[i].F-ind);
      |                                  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...