# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430807 | Belgutei | Wiring (IOI17_wiring) | C++17 | 53 ms | 8132 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 "wiring.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
pair<ll,ll> a[200005];
ll sum[200005],cnt;
ll dp[200005];
long long min_total_length(std::vector<int> red, std::vector<int> blue) {
for(int i=0; i<red.size(); i++){
cnt++;
a[cnt].ff=red[i];
a[cnt].ss=0;
}
for(int i=0; i<blue.size(); i++){
cnt++;
a[cnt].ff=blue[i];
a[cnt].ss=1;
}
sort(a+1,a+cnt+1);
for(int i=1; i<=cnt; i++){
sum[i]=sum[i-1]+a[i].ff;
}
a[0].ff=-1e9;
a[0].ss=1-a[1].ss;
for(int i=1, p=1; i<=cnt; i++){
int j=i;
while(j<cnt && a[j+1].ss==a[i].ss) j++;
for(int k=p; k<i; k++){
dp[k]=min(dp[k],dp[k-1]+a[i].ff-a[k].ff);
}
ll C=0,M=dp[i-1];
for(int k=i; k<=j; k++){
C+=a[k].ff-a[i-1].ff;
int x=2*i-k-2;
if(x+1>=p){
M=min(M,dp[x]+a[i-1].ff*(i-x-1)-(sum[i-1]-sum[x]));
}
dp[k]=M+C;
}
p=i;
i=j;
}
return dp[cnt];
}
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... |