Submission #216315

#TimeUsernameProblemLanguageResultExecution timeMemory
216315model_codeRuins 3 (JOI20_ruins3)C++17
100 / 100
434 ms12736 KiB
#include <iostream> const long long M=605,mod=1e9+7; int n,a[M]; long long C[2*M][2*M],F[M],dp[M][M]; int main(){ C[0][0]=F[0]=dp[0][0]=1; for(int i=0;i<2*M-1;i++) for(int j=0;j<=i;j++){ (C[i+1][j]+=C[i][j])%=mod; (C[i+1][j+1]+=C[i][j])%=mod; } for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",a+i); for(int i=0;i<n;i++) for(int j=0;j<=n;j++) if(dp[i][j]) for(int k=0;k<=std::min(n,a[i]-i-1)-j;k++){ (dp[i+1][j+k]+=dp[i][j]*C[2*k][k]%mod*C[a[i]-i-j-1][k]%mod*F[k]%mod*(k?1:j-i))%=mod; } long long res=dp[n][n]; for(int i=0;i<n;i++) (res*=mod/2+1)%=mod; printf("%lld\n",res); }

Compilation message (stderr)

ruins3.cpp: In function 'int main()':
ruins3.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
ruins3.cpp:15:28: 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("%d",a+i);
                       ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...