# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420895 | MDario | Wiring (IOI17_wiring) | C++11 | 1 ms | 204 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;
typedef long long ll;
#define F first
#define S second
long long min_total_length(vector<int> r, vector<int> b) {
ll n=r.size(), m=b.size(), c[20];
vector<pair<ll, bool>> v;
for(int i=0; i<n; i++)v.push_back({r[i], 0});
for(int i=0; i<m; i++)v.push_back({b[i], 1});
// if(r[0]<b[0])
v.push_back({0, 0});
// else v.push_back({0, 1});
sort(v.begin(), v.end());
ll dp[v.size()], a[v.size()];
c[0]=-1;
c[1]=-1;
dp[0]=0;
a[0]=0;
for(int i=1; i<v.size(); i++){
a[i]=v[i].F+a[i-1];
}
for(int i=1; i<v.size(); i++){
if(v[i].S==0){
if(c[1]==-1)dp[i]=1000000000000000ll;
else{
if(v[i-1].S==0){
dp[i]=a[i]-a[c[1]]-(i-c[1])*v[c[1]].F+min(dp[c[1]], dp[c[1]-1]);
}
else{
dp[i]=v[i].F-v[i-1].F+dp[i-1];
for(int t=i-1; v[t].S==1; t--)dp[i]=min(dp[i], v[i].F*(i-t)-(a[i-1]-a[t-1])+dp[t-1]);
}
}
c[0]=i;
}
else{
if(c[0]==-1)dp[i]=1000000000000000ll;
else{
if(v[i-1].S==1){
dp[i]=a[i]-a[c[0]]-(i-c[0])*v[c[0]].F+min(dp[c[0]], dp[c[0]-1]);
}
else{
dp[i]=v[i].F-v[i-1].F+dp[i-1];
for(int t=i-1; v[t].S==0; t--)dp[i]=min(dp[i], v[i].F*(i-t)-(a[i-1]-a[t-1])+dp[t-1]);
}
}
c[1]=i;
}
//cout << dp[i] << " ";
}
return dp[n+m];
}
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... |