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 ;
#define pb push_back
#define fi first
#define se second
typedef long long ll ;
typedef vector < int > vi ;
typedef pair < int , int > pi ;
typedef vector < pi > vpi ;
#include "wiring.h"
int n , m ;
vi a , b ;
ll dp [209][209] ;
ll bt ( int i , int j ) {
if ( i == n && j == m ) return 0ll ;
if ( i == n || j == m ) return 1e18 ;
ll &ret = dp [i][j] ;
if ( ret != -1 ) return ret ;
ret = 1e18 ;
ll cost = 0 ;
for ( ll nxt = j ; nxt < m ; nxt ++ ) {
cost += abs ( a [i] - b [nxt] ) ;
ret = min ( ret , bt ( i + 1 , nxt + 1 ) + cost ) ;
}
return ret ;
}
long long min_total_length ( vi A , vi B ) {
memset ( dp , -1 , sizeof (dp) ) ;
if ( A .size () > B .size () ) swap ( A , B ) ;
n = A .size () , m = B .size () ;
a = A , b = B ;
return bt ( 0 , 0 ) ;
}
# | 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... |