# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
20092 | | kk1401 | 괄호 (kriii4_R) | C++98 | | 17 ms | 24520 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<stdio.h>
#define M 1000000007ll
int n;
long long d[1000001],k,pow[1000001],comb[1000001];
int main()
{
int i;
scanf("%d%lld",&n,&k);
d[1] = k;
pow[0]=1ll;
for(i=1; i<=n; i++) pow[i] = (pow[i-1] * k) % M;
comb[1] = 2;
for(i=2; i<=n; i++) comb[i] = ((comb[i-1] / (long long)i) * (4ll*(long long)i - 2ll)) % M;
for(i=2; i<=n; i++){
if(i%2 == 0) d[i] = (d[i-1] * (k + 1ll)) % M;
else d[i] = (d[i-1] * (k + 1ll) - pow[(i-1)/2] * comb[(i-1)/2] / (((long long)i-1ll)/2ll+1ll) + M * M) % M;
}
printf("%lld\n",d[n]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |