# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72513 | 신딩없는 신딩팀 (#118) | Gorgeous Pill (FXCUP3_gorgeous) | C++14 | 29 ms | 10168 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 <stdio.h>
using namespace std;
int n;
long long c[1100],d[1100];
long long right[1100],left[1100];
long long ans[1100][1100];
long long dp(int l,int r)
{
if(ans[l][r]!=-1) return ans[l][r];
if(l==0) return right[r];
if(r==0) return left[l];
long long ret1=dp(l-1,r);
if(c[n-l]==n-l-r+1) ret1+=d[n-l];
long long ret2=dp(l,r-1);
if(c[r-1]==n-l-r+1) ret2+=d[r-1];
ans[l][r]=ret1>ret2?ret1:ret2;
//printf("%d %d %lld\n",l,r,ans[l][r]);
return ans[l][r];
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&c[i]);
for(int j=0;j<n;j++) scanf("%lld",&d[j]);
for(int j=1;j<n+1;j++)
if(n-j+1==c[j-1]) right[j]+=d[j-1];
for(int j=0;j<n;j++)
right[j+1]+=right[j];
for(int j=1;j<n+1;j++)
if(n-j+1==c[n-j]) left[j]+=d[n-j];
for(int j=0;j<n;j++)
left[j+1]+=left[j];
for(int i=0;i<1100;i++)
for(int j=0;j<1100;j++)
ans[i][j]=-1;
for(int i=0;i<n;i++)
{
if(c[i]==1)
printf("%lld ",dp(n-i-1,i)+d[i]);
else
printf("%lld ",dp(n-i-1,i));
}
}
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... |