# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
183957 | handlename | Wiring (IOI17_wiring) | C++17 | 2 ms | 376 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"
using namespace std;
#define pb push_back
#define mp make_pair
long long dp[200001],presum[200001];
vector<pair<int,int> > arr;
int prevv[200001];
long long min_total_length(vector<int> r,vector<int> b) {
int n=r.size()+b.size();
for (int i=0;i<r.size();i++){
arr.pb(mp(r[i],0));
}
for (int i=0;i<b.size();i++){
arr.pb(mp(b[i],1));
}
sort(arr.begin(),arr.end());
//dp[0]=1e18;
prevv[0]=-1;
presum[0]=arr[0].first;
for (int i=1;i<n;i++){
presum[i]=presum[i-1]+arr[i].first;
//dp[i]=1e18;
if (arr[i].second==arr[i-1].second) prevv[i]=prevv[i-1];
else prevv[i]=i-1;
if (prevv[i]==-1) continue;
dp[i]=dp[i-1]+arr[i].first-arr[prevv[i]].first;
if (prevv[prevv[i]]<prevv[i]-(i-prevv[i])+1){
long long cur=presum[i]-presum[prevv[i]];
cur-=(presum[prevv[i]]-presum[prevv[i]-(i-prevv[i])]);
if (prevv[i]-(i-prevv[i])!=-1) cur+=dp[prevv[i]-(i-prevv[i])];
dp[i]=min(dp[i],cur);
}
}
return dp[n-1];
}
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... |