#include <bits/stdc++.h>
using namespace std;
const int N=1000;
const long long INF=(long)1e18;
int K,L;
int memo[N][N];
int 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=K>=r-l+1?L:INF;
int last;
last=min(r,l+K-1);
for(int k=l;k<=last;k++){
ans=min(ans,2*teams[k]+dp(k+1,r));
}
last=max(l,r-K+1);
for(int k=r;k>=last;k--){
ans=min(ans,2*(L-teams[k])+dp(l,k-1));
}
return memo[l][r]=ans;
}
long long delivery(int a, int b, int c, int x[]) {
K=b;
L=c;
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
boxes.cpp: In function 'long long int dp(int, int)':
boxes.cpp:24:21: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return memo[l][r]=ans;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
15 ms |
4344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
4344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
15 ms |
4344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
15 ms |
4344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
15 ms |
4344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |