# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
298950 | infinite_iq | Wiring (IOI17_wiring) | C++14 | 1087 ms | 2936 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>
using namespace std ;
typedef long long ll ;
typedef vector < int > vi ;
#define lb lower_bound
#include "wiring.h"
long long min_total_length ( vi a , vi b ) {
if ( a .size () > b .size () ) swap ( a , b ) ;
int k = b .size () - a .size () ;
ll ans = 1e18 ;
ll N = ( !k ? b .size () : b .size () - k + 1 ) ;
for ( int i = 0 ; i < N ; i ++ ) {
ll cost = 0 ;
for ( int j = i ; j < i + k ; j ++ ) {
ll ret = 1e8 ;
auto it = lb ( a .begin () , a .end () , b [j] ) - a .begin () ;
if ( it != a .size () ) {
ret = min ( ret , (ll) ( abs ( a [it] - b [j] ) ) ) ;
}
it -- ;
if ( it != -1 ) {
ret = min ( ret , (ll) ( abs ( a [it] - b [j] ) ) ) ;
}
cost += ret ;
}
int it = 0 ;
for ( int j = 0 ; j < b .size () ; j ++ ) {
if ( i <= j && j < i + k ) continue ;
cost += abs ( b [j] - a [it++] ) ;
}
ans = min ( ans , cost ) ;
}
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... |