# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393605 | 79brue | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 129 ms | 134472 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;
int n; ll l;
ll arr[205], t[205];
ll DP[205][205][205][2]; /// l에 있는 경우 = 0, r에 있는 경우 = 1
int ans;
int main(){
scanf("%d %lld", &n, &l);
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
for(int i=1; i<=n; i++) scanf("%lld", &t[i]);
arr[n+1] = l;
for(int i=0; i<=n+3; i++) for(int j=0; j<=n+3; j++) for(int k=0; k<=n+3; k++) DP[i][j][k][0] = DP[i][j][k][1] = 1e18;
DP[0][n+1][0][0] = DP[0][n+1][0][1] = 0;
for(int d=n+1; d>0; d--){
for(int i=0; i<=n+1-d; i++){
int j = i+d;
for(int p=0; p<=n; p++){
ll newT; int newP;
if(DP[i][j][p][0] < 1e18){ /// 현재 i에 있는 경우
ans = max(ans, p);
if(d){
newT = DP[i][j][p][0] + (arr[i+1] - arr[i]);
newP = p + (newT <= t[i+1]);
DP[i+1][j][newP][0] = min(DP[i+1][j][newP][0], newT);
newT = DP[i][j][p][0] + l - (arr[j-1] - arr[i]);
newP = p + (newT <= t[j-1]);
DP[i][j-1][newP][1] = min(DP[i][j-1][newP][1], newT);
}
}
if(DP[i][j][p][1] < 1e18){
ans = max(ans, p);
if(d){
newT = DP[i][j][p][1] + l - (arr[j] - arr[i+1]);
newP = p + (newT <= t[i+1]);
DP[i+1][j][newP][0] = min(DP[i+1][j][newP][0], newT);
newT = DP[i][j][p][1] + (arr[j] - arr[j-1]);
newP = p + (newT <= t[j-1]);
DP[i][j-1][newP][1] = min(DP[i][j-1][newP][1], newT);
}
}
}
}
}
printf("%d", ans);
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |