이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define taskname "test"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 3005;
const int inf = 1e9 + 9;
int n, t;
int u[maxn], v[maxn], d[maxn], e[maxn];
int dp[maxn][maxn];
void read_input()
{
cin >> n >> t;
for(int i = 1; i <= n; ++i)
cin >> u[i] >> v[i] >> d[i] >> e[i];
}
void solve()
{
fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), inf);
dp[1][0] = 0;
for(int i = 1; i <= n; ++i)
for(int j = 0; j <= n; ++j)
{
if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + d[i] + v[i] - 2 * t * i);
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + u[i] + v[i]);
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + d[i] + v[i] - 2 * t * i);
if(j > 0) dp[i + 1][j - 1] = min(dp[i + 1][j - 1], dp[i][j] + u[i] + e[i] + 2 * t * i);
if(j > 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + d[i] + e[i]);
}
cout << (n + 1) * t + dp[n + 1][0] << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read_input();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |