# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1022961 | hirayuu_oj | Wiring (IOI17_wiring) | C++17 | 24 ms | 3932 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 rep(i,n) for(int i=0; i<(n); i++)
using ll=long long;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
if(r.size()<=1000&&b.size()<=1000){
if(r.size()<b.size())swap(r,b);
int n=r.size();
int m=b.size();
vector<ll> dp(m,1LL<<60);
dp[0]=abs(r[0]-b[0]);
for(int k=1; k<m; k++)dp[k]=dp[k-1]+abs(r[0]-b[k]);
for(int i=1; i<n; i++){
vector<ll> ndp(m,1LL<<60);
rep(j,m){
ndp[j]=min(ndp[j],dp[j]+abs(r[i]-b[j]));
ll cbl=0;
for(int k=j+1; k<m; k++){
cbl+=abs(r[i]-b[k]);
ndp[k]=min(ndp[k],dp[j]+cbl);
}
}
swap(dp,ndp);
}
return dp[m-1];
}
else{
ll ans=0;
rep(i,max(b.size(),r.size())){
ans+=abs(r[min((int)r.size()-1,i)]-b[max(0,(int)b.size()-1-i)]);
}
return ans;
}
}
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... |