# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31953 | minhtung0404 | 도장 모으기 (JOI14_stamps) | C++14 | 43 ms | 37384 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>
const int N = 3005;
const int inf = 1e9;
using namespace std;
int n, t, u[N][2], d[N][2];
int l[N][2], r[N][2], dp[N][N];
int main(){
scanf("%d %d", &n, &t);
for (int i = 1; i <= n; i++) scanf("%d %d %d %d", &u[i][0], &u[i][1], &d[i][0], &d[i][1]);
for (int i = 1; i <= n; i++){
r[i][0] = u[i][1]; l[i][0] = u[i][0];
r[i][1] = d[i][1]; l[i][1] = d[i][0];
for (int j = 1; j < i; j++){
r[i][0] = min(r[i][0], d[i][1]+2*t*(i-j)+d[j][0]+u[j][1]);
l[i][1] = min(l[i][1], 2*t*(i-j)+d[j][0]+u[j][1]+u[j][0]);
}
for (int j = i+1; j <= n; j++){
r[i][1] = min(r[i][1], u[i][1]+2*t*(j-i)+u[j][0]+d[j][1]);
l[i][0] = min(l[i][0], 2*t*(j-i)+u[j][0]+d[j][1]+d[j][0]);
}
r[i][0] -= t*i; l[i][0] += t*i;
r[i][1] += t*i; l[i][1] -= t*i;
}
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf;
dp[0][1] = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j <= n; j++){
if (dp[i][j] == inf) continue;
if (j > 1) dp[i+1][j] = min(dp[i+1][j] , dp[i][j]+l[i+1][1]+r[i+1][1]);
if (j > 0) dp[i+1][j] = min(dp[i+1][j] , dp[i][j]+l[i+1][0]+r[i+1][0]);
if (j > 1) dp[i+1][j-1] = min(dp[i+1][j-1], dp[i][j]+l[i+1][0]+r[i+1][1]);
if (j < n) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+l[i+1][1]+r[i+1][0]);
}
}
printf("%d", dp[n][1]+(n+1)*t);
}
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... |