Submission #800144

#TimeUsernameProblemLanguageResultExecution timeMemory
800144BenmathWiring (IOI17_wiring)C++14
0 / 100
1081 ms1660 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n=r.size(); int m=b.size(); if(n>m){ swap(r,b); swap(n,m); } if(n==m){ long long int sum=0; for(int i=0;i<n;i++){ sum=sum+abs(r[i]-b[i]); } return sum; } long long int sum=0; int kraj[n]; kraj[n-1]=m-1; for(int i=m-1;i>=(n-1);i--){ sum=sum+abs(r[n-1]-b[i]); } for(int i=n-2;i>=0;i--){ sum=sum+abs(r[i]-b[i]); kraj[i]=i; } for(int i=n-2;i>=0;i--){ for(int j=i+1;j<kraj[i+1];j++){ long long int ro=abs(r[i]-b[j]); long long int ro1=abs(r[i+1]-b[j]); if(ro<=ro1){ kraj[i]++; sum=sum-(ro1-ro); }else{ break;} } } return sum; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...