이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lp(i,a,b) for(int i = a ; i < b ; i++)
#define ll long long
#define ff first
#define ss second
const int MAXN = 1e7 + 5;
const int inf = 1e9 + 10 ;
using namespace std ;
//Declaracoes
int N , K , L ;
int pos[MAXN] ;
ll dp1[MAXN] , dp2[MAXN] ;
void print()
{
lp(i,0,N) cout<<dp1[i]<<" ";
cout<<endl ;
lp(i,0,N) cout<<dp2[i]<<" ";
cout<<endl;
}
//Funcao principal
ll delivery(int n , int k , int l , int positions[] )
{
//Globalizacao
N = n ; K = k ; L = l ;
lp(i,0,n) pos[i] = positions[i] ;
lp(i,0,n)
if( pos[i] == 0 ) pos[i] = inf , N-- ;
sort( pos , pos + n ) ;
n = N ;
lp(i,0,n)
{
dp1[i] = pos[i] * 2LL ;
if( i - k >= 0 ) dp1[i] += dp1[i-k] ;
}
for( int i = n-1 ; i >= 0 ; i-- )
{
dp2[i] = ( L - pos[i]) * 2LL ;
if( i + k < n ) dp2[i] += dp2[i+k] ;
}
ll best = 1LL * inf * MAXN ;
lp(i,0,n)
best = min( best , dp1[i] + dp2[i+1] ) ;
lp(i,0,n)
{
ll x = 0;
if( i + k < n ) x = dp2[i+k] ;
ll y = 0 ;
if( i-1 >= 0 ) y = dp1[i-1] ;
best = min( best , y + x + L ) ;
}
return best ;
}
# | 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... |