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 <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int mod = 1e9 + 7;
const int inf = 1e16;
const int N = 3005;
int add(int x, int y) {
return (1ll * x + 1ll * y) % mod;
}
int del(int x, int y) {
return ((1ll * x - 1ll * y) % mod + mod) % mod;
}
int mul(int x, int y) {
return (1ll * x * 1ll * y) % mod;
}
int dp[N][N], n, t, u[N], v[N], d[N], e[N], f[N][N], f1[N][N];
signed main() {
cin.tie(0), ios_base::sync_with_stdio(0);
cin >> n >> t;
for(int i = 1; i <= n; i++)
cin >> u[i] >> v[i] >> d[i] >> e[i];
//u[i] = nha cho len doc den cot tem
//v[i] = cot tem den nha cho tau len doc
//d[i] = nha cho tau xuong doc den cot tem
//e[i] = cot tem den nha tau xuong doc
for(int i = 0; i <= n + 1; i++) {
for(int j = 0; j <= n + 1; j++) {
dp[i][j] = inf;
}
}
dp[0][0] = 0;
for(int i = 0; i <= n + 1; i++) {
if(i > 0) {
for(int j = 0; j <= n + 1; j++) {
if(j)
dp[i][j] = min(dp[i][j], dp[i - 1][j] + d[i] + e[i] + 2 * j * t);
dp[i][j] = min(dp[i][j], dp[i - 1][j] + u[i] + v[i] + 2 * j * t);
if(j + 1 <= n + 1)
dp[i][j] = min(dp[i][j], f1[i - 1][j + 1] - j * (u[i] + e[i]));
if(j)
dp[i][j] = min(dp[i][j], f[i - 1][j - 1] + j * (d[i] + v[i]));
dp[i][j] += t;
// cout << dp[i][j] << " " << i << " " << j << "\n";
}
}
for(int j = 0; j <= n + 1; j++) {
f[i][j] = dp[i][j] + 2 * j * t - j * (d[i + 1] + v[i + 1]);
if(j)
f[i][j] = min(f[i][j], f[i][j - 1]);
}
for(int j = n + 1; j >= 0; j--) {
f1[i][j] = dp[i][j] + 2 * j * t + j * (u[i + 1] + e[i + 1]);
if(j + 1 <= n + 1)
f1[i][j] = min(f1[i][j], f1[i][j + 1]);
}
}
cout << dp[n][0] + t;
}
/*4 1
1 1 1 1
1 9 9 1
9 9 1 1
1 9 9 1*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |