Submission #20103

# Submission time Handle Problem Language Result Execution time Memory
20103 2016-02-25T13:34:56 Z kk1401 괄호 (kriii4_R) C++
0 / 100
159 ms 32332 KB
#include<stdio.h>
#define M 1000001
#define T 1000000007

long long power[M],k,fact[M],d[M],f[M];
int n;

long long Pow(long long a)
{
	long long i,t=1ll,c=0ll,ans=1ll;
	
	f[0] = a;
	for(i=1; ; i++){
		f[i] = (f[i-1] * f[i-1]) % T;
		t*=2ll;
		if(t>=T) break;
	}
	for(t = T-2;;){
		if(t&1) ans = (ans * f[c]) % T;
		c++; t/=2ll;
		if(t==0) break;
	}
	return ans;
}

long long catalan(int a)
{
	return (((Pow(a+1)*Pow(fact[a]))%T) * ((Pow(fact[a])*fact[2*a])%T))%T;
}

int main()
{
	int i;
	scanf("%d%lld",&n,&k);
	
	power[0] = fact[0] = 1; 
	for(i=1; i<=n; i++) power[i] = (power[i-1] * k) % T;
	for(i=1; i<=2*n; i++) fact[i] = (fact[i-1] * i) % T;
	
	d[1] = k;
	
	for(i=2; i<=n; i++){
		if(i%2 == 0) d[i] = d[i-1] * (k + 1ll) % T;
		else d[i] = ((d[i-1] * (k+1)) % M - (power[(i-1)/2] * catalan((i-1ll)/2ll)) % M + M) % M;
	}
	
	printf("%lld",d[n]);
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 159 ms 32332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -