#include<stdio.h>
int n, D[1010][1010], T;
int w[1010][4];
int main()
{
int i, j, g, h, M;
scanf("%d%d",&n,&T);
for(i=1;i<=n;i++){
scanf("%d%d%d%d",&w[i][0],&w[i][1],&w[i][2],&w[i][3]);
}
for(i=0;i<=n;i++){
for(j=0;j<n;j++){
D[i][j] = 2100000000;
}
}
D[0][0] = T;
for(i=1;i<=n;i++){
g=w[i][2]+w[i][1];
h=w[i][0]+w[i][1];
for(j=0;j<n;j++){
if(j && D[i][j] > M + (2*j+1)*T)D[i][j] = M + (2*j+1)*T;
if(D[i][j] > D[i-1][j] + h + (2*j+1)*T)D[i][j] = D[i-1][j] + h + (2*j+1)*T;
if(j == 0 || M > D[i-1][j]) M = D[i-1][j];
M += g;
}
g=w[i][0]+w[i][3];
h=w[i][2]+w[i][3];
for(j=n-1;j>=0;j--){
if(j != n-1 && D[i][j] > M + (2*j+1)*T)D[i][j] = M + (2*j+1)*T;
if(j && D[i][j] > D[i-1][j] + h + (2*j+1)*T)D[i][j] = D[i-1][j] + h + (2*j+1)*T;
if(j == n-1 || M > D[i-1][j]) M = D[i-1][j];
M += g;
}
}
printf("%d\n",D[n][0]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5088 KB |
Output is correct |
2 |
Correct |
0 ms |
5088 KB |
Output is correct |
3 |
Correct |
0 ms |
5088 KB |
Output is correct |
4 |
Correct |
0 ms |
5088 KB |
Output is correct |
5 |
Correct |
0 ms |
5088 KB |
Output is correct |
6 |
Correct |
0 ms |
5088 KB |
Output is correct |
7 |
Correct |
0 ms |
5088 KB |
Output is correct |
8 |
Correct |
0 ms |
5088 KB |
Output is correct |
9 |
Correct |
0 ms |
5088 KB |
Output is correct |
10 |
Correct |
0 ms |
5088 KB |
Output is correct |
11 |
Correct |
0 ms |
5088 KB |
Output is correct |
12 |
Correct |
0 ms |
5088 KB |
Output is correct |
13 |
Correct |
0 ms |
5088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5088 KB |
Output is correct |
2 |
Correct |
0 ms |
5088 KB |
Output is correct |
3 |
Correct |
0 ms |
5088 KB |
Output is correct |
4 |
Correct |
0 ms |
5088 KB |
Output is correct |
5 |
Correct |
0 ms |
5088 KB |
Output is correct |
6 |
Correct |
0 ms |
5088 KB |
Output is correct |
7 |
Correct |
0 ms |
5088 KB |
Output is correct |
8 |
Correct |
0 ms |
5088 KB |
Output is correct |
9 |
Correct |
0 ms |
5088 KB |
Output is correct |
10 |
Correct |
0 ms |
5088 KB |
Output is correct |
11 |
Correct |
0 ms |
5088 KB |
Output is correct |
12 |
Correct |
0 ms |
5088 KB |
Output is correct |
13 |
Correct |
0 ms |
5088 KB |
Output is correct |
14 |
Correct |
0 ms |
5088 KB |
Output is correct |
15 |
Correct |
0 ms |
5088 KB |
Output is correct |
16 |
Correct |
0 ms |
5088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
5084 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |