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, -1, sizeof(dp));
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]);
}
cout << f(n, 0) + t;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |