#include <cstdio>
#include <algorithm>
using namespace std;
int a[305],n;
int dp[305][205][205];
int f(int pos, int p1, int p2){
if(pos == n) return 0;
if(dp[pos][p1][p2]) return dp[pos][p1][p2];
int p3 = a[pos+2];
int ret = f(pos+1,p2,p3) + 3 * p1;
if(pos + 1 < n){
int cut = min(p1,p2);
ret = min(ret,f(pos+1,p2-cut,p3) + 5 * cut +3 * (p1 - cut));
}
if(pos + 2 < n){
int cut = min(p1,min(p2,p3));
ret = min(ret,f(pos+1,p2-cut,p3-cut) + 7 * cut + 3 * (p1 - cut));
}
return dp[pos][p1][p2] = ret;
}
int main(){
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d",&a[i]);
}
printf("%d",f(0,a[0],a[1]));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
51152 KB |
Output is correct |
2 |
Correct |
0 ms |
51152 KB |
Output is correct |
3 |
Correct |
0 ms |
51152 KB |
Output is correct |
4 |
Correct |
0 ms |
51152 KB |
Output is correct |
5 |
Correct |
0 ms |
51152 KB |
Output is correct |
6 |
Incorrect |
0 ms |
51152 KB |
Output isn't correct |
7 |
Correct |
0 ms |
51152 KB |
Output is correct |
8 |
Correct |
0 ms |
51152 KB |
Output is correct |
9 |
Incorrect |
0 ms |
51152 KB |
Output isn't correct |
10 |
Correct |
0 ms |
51152 KB |
Output is correct |
11 |
Incorrect |
0 ms |
51152 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
51152 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
51152 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
51152 KB |
Output isn't correct |
15 |
Incorrect |
12 ms |
51152 KB |
Output isn't correct |
16 |
Incorrect |
14 ms |
51152 KB |
Output isn't correct |
17 |
Correct |
0 ms |
51152 KB |
Output is correct |
18 |
Incorrect |
49 ms |
51152 KB |
Output isn't correct |
19 |
Correct |
41 ms |
51152 KB |
Output is correct |
20 |
Incorrect |
32 ms |
51152 KB |
Output isn't correct |