Submission #72513

#TimeUsernameProblemLanguageResultExecution timeMemory
72513신딩없는 신딩팀 (#118)Gorgeous Pill (FXCUP3_gorgeous)C++14
51 / 100
29 ms10168 KiB
#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)

gorgeous.cpp: In function 'int main()':
gorgeous.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
gorgeous.cpp:24:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++) scanf("%lld",&c[i]);
                          ~~~~~^~~~~~~~~~~~~~
gorgeous.cpp:25:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int j=0;j<n;j++) scanf("%lld",&d[j]);
                          ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...