# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924685 | Dzadzo | Wiring (IOI17_wiring) | C++14 | 44 ms | 8896 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |