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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
int dp[3005][3005];
int n, t, a[3005], b[3005], c[3005], d[3005];
int f(int pos, int stk){
if(pos == 0) return stk == 0 ? 0 : 1e9;
if(~dp[pos][stk]) return dp[pos][stk];
int ret = 1e9;
ret = min(ret, f(pos - 1, stk) + t + a[pos] + b[pos] + 2 * stk * t);
if(stk) ret = min(ret, f(pos - 1, stk) + t + c[pos] + d[pos] + 2 * stk * t);
ret = min(ret, f(pos - 1, stk + 1) + t + a[pos] + d[pos] + 2 * (stk + 1) * t);
for(int j=0; j<stk; j++){
ret = min(ret, f(pos - 1, j) + t + (stk - j) * (b[pos] + c[pos]) + 2 * j * t);
}
return dp[pos][stk] = ret;
}
int main(){
memset(dp[0], 0x3f, sizeof(dp[0]));
scanf("%d %d",&n,&t);
for(int i=1; i<=n; i++){
scanf("%d %d %d %d",&a[i], &b[i], &c[i], &d[i]);
}
dp[0][0] = t;
for(int i=1; i<=n; i++){
for(int j=0; j<=n; j++){
dp[i][j] = dp[i-1][j] + t + a[i] + b[i] + 2 * j * t;
if(j < n) dp[i][j] = min(dp[i][j], dp[i-1][j+1] + t + a[i] + d[i] + 2 * (j+1) * t);
if(j) dp[i][j] = min(dp[i][j], dp[i-1][j] + t + c[i] + d[i] + 2 * j * t);
for(int k=0; k<j; k++){
dp[i][j] = min(dp[i][j], dp[i-1][k] + t + (j-k) * (b[i] + c[i]) + 2 * k * t);
}
}
}
printf("%d",dp[n][0]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |