# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72391 | (#118) | Gorgeous Pill (FXCUP3_gorgeous) | C++14 | 501 ms | 14456 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 <cstdio>
#include <algorithm>
using namespace std;
long long dp[2][1002][1002]; // 너비, 구간 시작점, 첫 약
int C[1002];
int D[1002];
int main(){
int N; scanf("%d", &N);
if(N > 1000){
puts("Subtask 3");
return 0;
}
for(int i = 1; i <= N; i++) scanf("%d", &C[i]);
for(int i = 1; i <= N; i++) scanf("%d", &D[i]);
for(int i = 1; i <= N; i++) dp[1][i][i] = (C[i] == 1 ? D[i] : 0);
for(int w = 2; w <= N; w++){
int w_ = w & 1, _w = w_ ^ 1;
int e = N - w + 1;
for(int i = 1; i <= e; i++){
int fe = i + w - 1;
for(int f = i; f <= fe; f++){
// 마지막 약으로 구간의 시작점 or 구간의 끝점
long long a = f < fe ? dp[_w][i][f] + (C[fe] == w ? D[fe] : 0) : 0;
long long b = f > i ? dp[_w][i + 1][f] + (C[i] == w ? D[i] : 0) : 0;
dp[w_][i][f] = max(a, b);
}
}
}
for(int i = 1; i <= N; i++) printf("%lld ", dp[N & 1][1][i]);
printf("\n");
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... |