답안 #595285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595285 2022-07-13T14:24:40 Z Koosha_mv 유적 3 (JOI20_ruins3) C++14
100 / 100
1249 ms 11644 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=1205,mod=1e9+7,inv2=mod/2+1;

int n,t,f[N],g[N],fact[N],ps[N][N],C[N][N],dp[N][N],mark[N];
vector<int> A,B;

ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}

int G(int n){
	if(n==0) return 1;
	return (C[n][2*n]-C[n-1][2*n]+mod)%mod;
}
int c(int k,int n){
	if(k<0 || k>n) return 0;
	return C[k][n];
}

int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	fact[0]=1;
	f(i,0,N){
		C[0][i]=1;
		f(j,1,i+1) C[j][i]=(C[j-1][i-1]+C[j][i-1])%mod;
		if(i>0) fact[i]=1ll*fact[i-1]*i%mod;
	}
	g[1]=f[1]=1;
	f(i,2,N){
		f(j,0,i/2+1){
			int res=1ll*C[2*j][i]*G(j)%mod*pow(inv2,2*j,mod)%mod;
			res=1ll*res*fact[i]%mod*fact[i]%mod;
			Add(g[i],res);
		}
		f[i]=g[i];
		f(j,1,i){
			Add(f[i],mod-1ll*f[j]*g[i-j]%mod*C[j][i]%mod*C[j-1][i-1]%mod);
		}
	}
	cin>>n;
	f(i,1,n+1){
		int x;
		cin>>x;
		mark[x]=1;
	}
	f(i,1,2*n+1){
		if(mark[i]) A.pb(i);
		else B.pb(i);
	}
	dp[0][0]=1;
	f(i,0,n+1) ps[0][i]=1;
	f(i,1,n+1){
		f(j,1,i+1){
			f(k,0,i){
				int x=lower_bound(all(B),A[j-1])-B.begin()-k;
				int res=1ll*ps[k][j-1]*c(i-k-1,(n+1-j)-(n-i)-1)%mod*f[i-k]%mod;
				res=1ll*res*c(i-k,x)%mod;
				Add(dp[i][j],res);
				}
			}
		f(j,1,n+1) ps[i][j]=(ps[i][j-1]+dp[i][j])%mod;
	}
	int ans=0;
	f(i,1,n+1) Add(ans,dp[n][i]);
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5964 KB Output is correct
2 Correct 33 ms 5952 KB Output is correct
3 Correct 34 ms 6024 KB Output is correct
4 Correct 34 ms 5960 KB Output is correct
5 Correct 39 ms 5964 KB Output is correct
6 Correct 35 ms 5964 KB Output is correct
7 Correct 58 ms 5948 KB Output is correct
8 Correct 36 ms 5960 KB Output is correct
9 Correct 34 ms 5964 KB Output is correct
10 Correct 31 ms 5968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5964 KB Output is correct
2 Correct 33 ms 5952 KB Output is correct
3 Correct 34 ms 6024 KB Output is correct
4 Correct 34 ms 5960 KB Output is correct
5 Correct 39 ms 5964 KB Output is correct
6 Correct 35 ms 5964 KB Output is correct
7 Correct 58 ms 5948 KB Output is correct
8 Correct 36 ms 5960 KB Output is correct
9 Correct 34 ms 5964 KB Output is correct
10 Correct 31 ms 5968 KB Output is correct
11 Correct 33 ms 6348 KB Output is correct
12 Correct 36 ms 6348 KB Output is correct
13 Correct 35 ms 6344 KB Output is correct
14 Correct 33 ms 6352 KB Output is correct
15 Correct 39 ms 6348 KB Output is correct
16 Correct 48 ms 6464 KB Output is correct
17 Correct 44 ms 6488 KB Output is correct
18 Correct 32 ms 6348 KB Output is correct
19 Correct 32 ms 6348 KB Output is correct
20 Correct 36 ms 6348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5964 KB Output is correct
2 Correct 33 ms 5952 KB Output is correct
3 Correct 34 ms 6024 KB Output is correct
4 Correct 34 ms 5960 KB Output is correct
5 Correct 39 ms 5964 KB Output is correct
6 Correct 35 ms 5964 KB Output is correct
7 Correct 58 ms 5948 KB Output is correct
8 Correct 36 ms 5960 KB Output is correct
9 Correct 34 ms 5964 KB Output is correct
10 Correct 31 ms 5968 KB Output is correct
11 Correct 33 ms 6348 KB Output is correct
12 Correct 36 ms 6348 KB Output is correct
13 Correct 35 ms 6344 KB Output is correct
14 Correct 33 ms 6352 KB Output is correct
15 Correct 39 ms 6348 KB Output is correct
16 Correct 48 ms 6464 KB Output is correct
17 Correct 44 ms 6488 KB Output is correct
18 Correct 32 ms 6348 KB Output is correct
19 Correct 32 ms 6348 KB Output is correct
20 Correct 36 ms 6348 KB Output is correct
21 Correct 853 ms 11644 KB Output is correct
22 Correct 910 ms 11548 KB Output is correct
23 Correct 839 ms 11568 KB Output is correct
24 Correct 858 ms 11556 KB Output is correct
25 Correct 839 ms 11568 KB Output is correct
26 Correct 811 ms 11488 KB Output is correct
27 Correct 779 ms 11588 KB Output is correct
28 Correct 790 ms 11644 KB Output is correct
29 Correct 584 ms 11632 KB Output is correct
30 Correct 1213 ms 11524 KB Output is correct
31 Correct 1008 ms 11492 KB Output is correct
32 Correct 1135 ms 11468 KB Output is correct
33 Correct 1249 ms 11568 KB Output is correct
34 Correct 1026 ms 11580 KB Output is correct
35 Correct 1092 ms 11464 KB Output is correct
36 Correct 1150 ms 11576 KB Output is correct