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;
const int N=1000;
const long long INF=(long)1e18;
long long K,L;
int memo[N][N];
long long teams[N];
long long dist[N][N];
long long dp(int l,int r) {
if(l>r)
return 0;
if(memo[l][r]!=-1)
return memo[l][r];
long long ans=INF;
if(r-l+1<=K)
ans=L;
for(int k=l;k<=r;k++){
if(k-l+1>K) break;
ans=min(ans,teams[k]+dp(k+1,r)+min(teams[k],L-teams[k]));
}
for(int k=r;k>=l;k--){
if(r-k+1>K)
break;
ans=min(ans,L-teams[k]+dp(l,k-1)+min(L-teams[k],teams[k]));
}
return memo[l][r]=ans;
}
long long delivery(int a, int b, int c, int x[]) {
K=b;
L=c;
sort(x,x+a);
for(int i=0;i<a;i++){
teams[i]=x[i];
for(int j=0;j<a;j++)
memo[i][j]=-1;
}
return dp(0,a-1);
}
Compilation message (stderr)
boxes.cpp: In function 'long long int dp(int, int)':
boxes.cpp:26:21: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return memo[l][r]=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... |