# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72229 | 마릴린 희정 (#118) | Gorgeous Pill (FXCUP3_gorgeous) | C++14 | 16 ms | 9560 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 lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 1050;
lint dp[MAXN][MAXN];
int n, a[MAXN], b[MAXN];
lint f(int s, int e){
if(~dp[s][e]) return dp[s][e];
lint ret = 0;
if(s > 1){
ret = max(ret, f(s - 1, e) + (a[s - 1] == (e - s + 2) ? b[s - 1] : 0));
}
if(e < n){
ret = max(ret, f(s, e + 1) + (a[e + 1] == (e - s + 2) ? b[e + 1] : 0));
}
return dp[s][e] = ret;
}
int main(){
scanf("%d",&n);
if(n > 1000 ) return 0;
for(int i=1; i<=n; i++) scanf("%d",&a[i]);
for(int i=1; i<=n; i++) scanf("%d",&b[i]);
memset(dp, -1, sizeof(dp));
for(int i=1; i<=n; i++){
lint ans = f(i, i);
if(a[i] == 1) ans += b[i];
printf("%lld ", 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... |