# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156066 | EntityIT | 도장 모으기 (JOI14_stamps) | C++14 | 279 ms | 141952 KiB |
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;
typedef long long LL;
const LL infLL = (LL)1e18 + 123;
const int N = (int)3e3 + 5;
void assignMin(LL &a, LL b) {
a = min(a, b);
}
int n, t, u[N], v[N], d[N], e[N];
LL dp[2][N][N];
int main() {
scanf(" %d %d", &n, &t);
for (int i = 1; i <= n; ++i) scanf(" %d %d %d %d", u + i, v + i, d + i, e + i);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) dp[0][i][j] = dp[1][i][j] = infLL;
}
dp[0][1][0] = t;
for (int i = 1; i <= n; ++i) {
for (int j = n; j > 0; --j) assignMin(dp[1][i][j - 1], dp[0][i][j] + u[i] + e[i]);
for (int j = n; j > 0; --j) assignMin(dp[1][i][j - 1], dp[1][i][j] + u[i] + e[i]);
for (int j = 0; j < n; ++j) assignMin(dp[1][i][j + 1], dp[0][i][j] + d[i] + v[i]);
for (int j = 0; j < n; ++j) assignMin(dp[1][i][j + 1], dp[1][i][j] + d[i] + v[i]);
for (int j = 0; j <= n; ++j) {
assignMin(dp[1][i][j], dp[0][i][j] + u[i] + v[i]);
if (j) assignMin(dp[1][i][j], dp[0][i][j] + d[i] + e[i]);
}
for (int j = 0; j <= n; ++j) assignMin(dp[0][i + 1][j], dp[1][i][j] + t + 2 * j * t);
}
printf("%lld", dp[1][n][0] + t);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |