# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420042 | chirathnirodha | Wiring (IOI17_wiring) | C++17 | 32 ms | 3116 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;
int dp[500][500];
long long min_total_length(vector<int> r, vector<int> b) {
int n=r.size(),m=b.size();
if(n<=200 && m<=200){
dp[0][0]=abs(r[0]-b[0]);
for(int i=1;i<m;i++)dp[0][i]=dp[0][i-1]+abs(r[0]-b[i]);
for(int i=1;i<n;i++)dp[i][0]=dp[i-1][0]+abs(r[i]-b[0]);
for(int i=1;i<n;i++) for(int j=1;j<m;j++) dp[i][j]=min(min(dp[i][j-1],dp[i-1][j]),dp[i-1][j-1])+abs(r[i]-b[j]);
return dp[n-1][m-1];
}
else{
int jj=0;
int ii=0;
long long sum=0;
for(ii;ii<n && jj<m;ii++,jj++){
sum+=b[jj]-r[ii];
}
for(ii;ii<n;ii++)sum+=b[0]-r[ii];
for(jj;jj<m;jj++)sum+=b[jj]-r[n-1];
return sum;
}
}
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... |