이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std;
long long n , k , l , a [10000007] , b [10000007] , adp [2003][2005] , bdp [2003][2005];
long long dlta ( long long x , long long y )
{
return abs ( x - y );
}
long long delivery(int N, int K, int L, int p[]) {
n = N , k = K , l = L;
for ( int i = 1 ; i <= n + 1 ; i ++ )
{
for ( int j = 0 ; j <= n + 2 ; j ++ )
{
adp [i][j] = 1e18;
bdp [i][j] = 1e18;
}
if ( i != n + 1 )
{
a [i] = p [ i - 1 ];
b [i] = a [i];
}
}
long long ans = 1e18;
adp [0][k] = 0;
for ( int i = 1 ; i <= n ; i ++ )
{
for ( int j = 1 ; j < k ; j ++ )
{
adp [i][ j - 1 ] = min ( adp [i][ j - 1 ] , adp [ i - 1 ][j] + dlta ( a [i] , a [ i - 1 ] ) );
adp [i][k] = min ( adp [i][k] , adp [i][ j - 1 ] + dlta ( a [i] , 0 ) );
}
adp [i][ k - 1 ] = min ( adp [i][ k - 1 ] , adp [ i - 1 ][k] + dlta ( a [i] , 0 ) );
adp [i][k] = min ( adp [i][k] , adp [i][ k - 1 ] + dlta ( a [i] , 0 ) );
}
reverse ( a + 1 , a + n + 1 );
bdp [0][k] = 0;
for ( int i = 1 ; i <= n ; i ++ )
{
for ( int j = 1 ; j < k ; j ++ )
{
bdp [i][ j - 1 ] = min ( bdp [i][ j - 1 ] , bdp [ i - 1 ][j] + dlta ( a [i] , a [ i - 1 ] ) );
bdp [i][k] = min ( bdp [i][k] , bdp [i][ j - 1 ] + dlta ( a [i] , 0 ) );
}
bdp [i][ k - 1 ] = min ( bdp [i][ k - 1 ] , bdp [ i - 1 ][k] + dlta ( a [i] , 0 ) );
bdp [i][k] = min ( bdp [i][k] , bdp [i][ k - 1 ] + dlta ( a [i] , 0 ) );
}
for ( int i = 0 ; i <= n ; i ++ )
{
long long ada = adp [i][k] , adb = bdp [ n - i ][k];
for ( int j = 1 ; j < k ; j ++ ) ada = min ( ada , adp [i][j] + dlta ( b [i] , 0 ) );
for ( int j = 1 ; j < k ; j ++ ) adb = min ( adb , bdp [ n - i ][j] + dlta ( a [ n - i ] , 0 ) );
ans = min ( ans , ada + adb );
}
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |