Submission #19028

#TimeUsernameProblemLanguageResultExecution timeMemory
19028gs14004도장 모으기 (JOI14_stamps)C++14
85 / 100
1000 ms37148 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...