Submission #763677

# Submission time Handle Problem Language Result Execution time Memory
763677 2023-06-22T15:24:15 Z amirhoseinfar1385 Ruins 3 (JOI20_ruins3) C++17
100 / 100
795 ms 11592 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=605,tmaxn=1205;
int mod=1e9+7;
long long mypow(long long m,long long y){
	if(y==0){
		return 1;
	}
	long long p=mypow(m,(y>>1));
	p*=p;
	p%=mod;
	if(y&1){
		p*=m;
		p%=mod;
	}
	return p;
}
int fact[tmaxn],revfact[tmaxn],magemishe[tmaxn],res[tmaxn][tmaxn],dp[tmaxn],n;
int c[tmaxn][tmaxn];
int vas[tmaxn];
int ww(int a){
	if(a>=mod){
		a-=mod;
	}
	return a;
}

void aval(){
	fact[0]=1;
	for(int i=1;i<tmaxn;i++){
		fact[i]=1ll*fact[i-1]*i%mod;
	}
	revfact[tmaxn-1]=mypow(fact[tmaxn-1],mod-2);
	for(int i=tmaxn-2;i>=0;i--){
		revfact[i]=1ll*revfact[i+1]*(i+1)%mod;
	}
	for(int i=0;i<tmaxn;i++){
		c[i][0]=1;
	}	
	for(int i=1;i<tmaxn;i++){
		for(int j=1;j<tmaxn;j++){
			c[i][j]=c[i-1][j-1]+c[i-1][j];
			c[i][j]=ww(c[i][j]);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	aval();
	cin>>n;
	for(int i=0;i<n;i++){
		int d;
		cin>>d;
		vas[d]=1;
	}
	dp[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			dp[i]+=1ll*c[i-1][j-1]*(i-j+2)%mod*dp[i-j]%mod*dp[j-1]%mod;
			dp[i]=ww(dp[i]);
		}
	}
	res[n*2+1][0]=1;
	int oomade=0,naumade=0;
	for(int i=n*2;i>=1;i--){
		if(vas[i]){
			for(int j=0;j<=oomade+1;j++){
				res[i][j]=res[i+1][j];
				for(int h=1;h<=j;h++){
					res[i][j]+=1ll*res[i+1][h-1]*dp[j-h]%mod*c[oomade-h+1][j-h]%mod*(j-h+2)%mod;
					res[i][j]=ww(res[i][j]);
				}
			}
			oomade++;
		}
		else{
			for(int j=0;j<=oomade;j++){
				res[i][j]=1ll*res[i+1][j]*max(j-naumade,0)%mod;
			}
			naumade++;
		}
	}
	int mainres=1ll*res[1][n]*mypow(mypow(2,n),mod-2)%mod;
	cout<<mainres<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5972 KB Output is correct
2 Correct 4 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 4 ms 6100 KB Output is correct
5 Correct 4 ms 6100 KB Output is correct
6 Correct 4 ms 6040 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5972 KB Output is correct
2 Correct 4 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 4 ms 6100 KB Output is correct
5 Correct 4 ms 6100 KB Output is correct
6 Correct 4 ms 6040 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 4 ms 6484 KB Output is correct
12 Correct 4 ms 6484 KB Output is correct
13 Correct 4 ms 6484 KB Output is correct
14 Correct 4 ms 6496 KB Output is correct
15 Correct 5 ms 6484 KB Output is correct
16 Correct 4 ms 6484 KB Output is correct
17 Correct 4 ms 6400 KB Output is correct
18 Correct 5 ms 6484 KB Output is correct
19 Correct 4 ms 6484 KB Output is correct
20 Correct 5 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5972 KB Output is correct
2 Correct 4 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 4 ms 6100 KB Output is correct
5 Correct 4 ms 6100 KB Output is correct
6 Correct 4 ms 6040 KB Output is correct
7 Correct 4 ms 6100 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6100 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 4 ms 6484 KB Output is correct
12 Correct 4 ms 6484 KB Output is correct
13 Correct 4 ms 6484 KB Output is correct
14 Correct 4 ms 6496 KB Output is correct
15 Correct 5 ms 6484 KB Output is correct
16 Correct 4 ms 6484 KB Output is correct
17 Correct 4 ms 6400 KB Output is correct
18 Correct 5 ms 6484 KB Output is correct
19 Correct 4 ms 6484 KB Output is correct
20 Correct 5 ms 6484 KB Output is correct
21 Correct 480 ms 11556 KB Output is correct
22 Correct 478 ms 11524 KB Output is correct
23 Correct 478 ms 11520 KB Output is correct
24 Correct 483 ms 11500 KB Output is correct
25 Correct 481 ms 11588 KB Output is correct
26 Correct 479 ms 11500 KB Output is correct
27 Correct 479 ms 11540 KB Output is correct
28 Correct 481 ms 11540 KB Output is correct
29 Correct 478 ms 11184 KB Output is correct
30 Correct 795 ms 11536 KB Output is correct
31 Correct 635 ms 11592 KB Output is correct
32 Correct 710 ms 11584 KB Output is correct
33 Correct 770 ms 11492 KB Output is correct
34 Correct 633 ms 11572 KB Output is correct
35 Correct 713 ms 11512 KB Output is correct
36 Correct 770 ms 11576 KB Output is correct