# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20190 | rlatnwls | 괄호 (kriii4_R) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include cstdio>
const long long mod = 1000000007;
long long t1[1000002],c[1000002];
int main()
{
int n,k; scanf ("%d %d",&n,&k);
t1[1] = 1;
for (int i=2;i<=n/2+1;i++) t1[i] = (1 - 1 / i) * t1[i] % mod;
//catalan에서 1/n+1부분??
c[0] = 1;
for (int i=1;i<=n/2;i++) c[i] = 2*(2 * i - 1) * t1[i+1] % mod * c[i-1] % mod;//전의 c[i-1]에서 곱할 계수?
long long u = 1;
for (int i=1;i<=n/2;i++){
u = u * k % mod;
c[i] = c[i] * u % mod;
}//k^n/2부분??
long long res = 1ll;
for (int i=0;i<n;i++){
res = res * (k + 1) % mod;
if (i % 2 == 0) res = (res - c[i/2]) % mod;
}
printf ("%lld\n",res);
return 0;
}