# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
296787 | DanerZein | Wiring (IOI17_wiring) | C++14 | 35 ms | 3960 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>
#define MAX 1000000000000000000
using namespace std;
typedef long long ll;
ll dp[210][210];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
int n,m;
n=r.size();
m=b.size();
int j;
if(n<=200 and m<=200){
dp[0][0]=abs(r[0]-b[0]);
for(int i=0;i<n;i++){
if(i==0) j=1;
else j=0;
for(;j<m;j++){
ll rp=MAX;
if(i-1>=0 and j-1>=0){
rp=min(rp,dp[i-1][j-1]);
}
if(i-1>=0){
rp=min(rp,dp[i-1][j]);
}
if(j-1>=0){
rp=min(rp,dp[i][j-1]);
}
dp[i][j]=rp+abs(r[i]-b[j]);
}
}
return dp[n-1][m-1];
}
else{
ll res=0;
int l=0,ri=b.size()-1;
while(true){
res+=abs(r[l]-b[ri]);
if(l==r.size()-1 and ri==0) break;
if(l!=r.size()-1) l++;
if(ri!=0) ri--;
}
/*if(n>m){
int j=b.size()-1;
for(int i=0;i<r.size();i++){
if(j!=0) j--;
res+=abs(r[i]-b[j]);
}
}
else{
int j=0;
for(int i=b.size()-1;i>=0;i--){
if(j!=r.size()-1) j++;
res+=abs(b[i]-r[j]);
}
}*/
return res;
}
}
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... |