# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48318 | choikiwon | 도장 모으기 (JOI14_stamps) | C++17 | 142 ms | 796 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;
const int MN = 3010;
int N, T;
int U[MN], V[MN], D[MN], E[MN];
int dp[2][MN][2][2];
int main() {
scanf("%d %d", &N, &T);
for(int i = 0; i < N; i++) {
scanf("%d %d %d %d", &U[i], &V[i], &D[i], &E[i]);
}
for(int i = 1; i <= N; i++) dp[N & 1][i][1][0] = 1e9;
for(int i = N - 1; i >= 0; i--) {
for(int t = 0; t < 2; t++) {
if(t) {
for(int open = N; open >= 0; open--) {
for(int d = 0; d < 2; d++) {
dp[i & 1][open][t][d] = 1e9;
if(open < N) dp[i & 1][open][t][d] = min(dp[i & 1][open][t][d], dp[i & 1][open + 1][1][d | 1] + V[i] + D[i]);
dp[i & 1][open][t][d] = min(dp[i & 1][open][t][d], dp[i & 1][open][0][d]);
}
}
}
else {
for(int open = 0; open <= N; open++) {
for(int d = 0; d < 2; d++) {
dp[i & 1][open][t][d] = 1e9;
if(open) dp[i & 1][open][t][d] = min(dp[i & 1][open][t][d], dp[i & 1][open - 1][0][d | 1] + U[i] + E[i]);
if(d) dp[i & 1][open][t][d] = min(dp[i & 1][open][t][d], dp[ (i ^ 1) & 1 ][open][1][0] + T * (2 * open + 1));
else {
int cost = U[i] + V[i];
if(open) cost = min(cost, D[i] + E[i]);
dp[i & 1][open][t][d] = min(dp[i & 1][open][t][d], dp[ (i ^ 1) & 1 ][open][1][0] + cost + T * (2 * open + 1));
}
}
}
}
}
}
printf("%d", T + dp[0][0][1][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... |