Submission #216315

# Submission time Handle Problem Language Result Execution time Memory
216315 2020-03-27T05:12:18 Z model_code Ruins 3 (JOI20_ruins3) C++17
100 / 100
434 ms 12736 KB
#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

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 time Memory Grader output
1 Correct 14 ms 9984 KB Output is correct
2 Correct 17 ms 9984 KB Output is correct
3 Correct 14 ms 9984 KB Output is correct
4 Correct 14 ms 9984 KB Output is correct
5 Correct 14 ms 9984 KB Output is correct
6 Correct 28 ms 9976 KB Output is correct
7 Correct 13 ms 9984 KB Output is correct
8 Correct 32 ms 9976 KB Output is correct
9 Correct 16 ms 9984 KB Output is correct
10 Correct 13 ms 9984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9984 KB Output is correct
2 Correct 17 ms 9984 KB Output is correct
3 Correct 14 ms 9984 KB Output is correct
4 Correct 14 ms 9984 KB Output is correct
5 Correct 14 ms 9984 KB Output is correct
6 Correct 28 ms 9976 KB Output is correct
7 Correct 13 ms 9984 KB Output is correct
8 Correct 32 ms 9976 KB Output is correct
9 Correct 16 ms 9984 KB Output is correct
10 Correct 13 ms 9984 KB Output is correct
11 Correct 30 ms 10144 KB Output is correct
12 Correct 17 ms 10112 KB Output is correct
13 Correct 34 ms 10104 KB Output is correct
14 Correct 17 ms 10112 KB Output is correct
15 Correct 16 ms 9856 KB Output is correct
16 Correct 13 ms 10112 KB Output is correct
17 Correct 14 ms 9856 KB Output is correct
18 Correct 15 ms 10240 KB Output is correct
19 Correct 27 ms 10104 KB Output is correct
20 Correct 14 ms 10112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9984 KB Output is correct
2 Correct 17 ms 9984 KB Output is correct
3 Correct 14 ms 9984 KB Output is correct
4 Correct 14 ms 9984 KB Output is correct
5 Correct 14 ms 9984 KB Output is correct
6 Correct 28 ms 9976 KB Output is correct
7 Correct 13 ms 9984 KB Output is correct
8 Correct 32 ms 9976 KB Output is correct
9 Correct 16 ms 9984 KB Output is correct
10 Correct 13 ms 9984 KB Output is correct
11 Correct 30 ms 10144 KB Output is correct
12 Correct 17 ms 10112 KB Output is correct
13 Correct 34 ms 10104 KB Output is correct
14 Correct 17 ms 10112 KB Output is correct
15 Correct 16 ms 9856 KB Output is correct
16 Correct 13 ms 10112 KB Output is correct
17 Correct 14 ms 9856 KB Output is correct
18 Correct 15 ms 10240 KB Output is correct
19 Correct 27 ms 10104 KB Output is correct
20 Correct 14 ms 10112 KB Output is correct
21 Correct 32 ms 12408 KB Output is correct
22 Correct 16 ms 12416 KB Output is correct
23 Correct 17 ms 12416 KB Output is correct
24 Correct 23 ms 12416 KB Output is correct
25 Correct 16 ms 9856 KB Output is correct
26 Correct 15 ms 9856 KB Output is correct
27 Correct 15 ms 9856 KB Output is correct
28 Correct 15 ms 12288 KB Output is correct
29 Correct 15 ms 9836 KB Output is correct
30 Correct 434 ms 12664 KB Output is correct
31 Correct 228 ms 12664 KB Output is correct
32 Correct 324 ms 12640 KB Output is correct
33 Correct 406 ms 12640 KB Output is correct
34 Correct 227 ms 12664 KB Output is correct
35 Correct 326 ms 12736 KB Output is correct
36 Correct 414 ms 12612 KB Output is correct