Submission #20173

# Submission time Handle Problem Language Result Execution time Memory
20173 2016-03-01T06:10:08 Z sui 괄호 (kriii4_R) C++14
8 / 100
127 ms 48604 KB
#define _CRT_SECURE_NO_WARNINGS // scanf(), gets() (needed for Visual C++)

//#define NDEBUG
#include <cassert>

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>

#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <deque>


using namespace std;

#define MEMSET(x, WITH) memset(x, (WITH), sizeof(x))
#define FOR(i, E) for(int i=0; i<(E); i++)
#define REP(i, LO, HI) for(int i=(LO); i<=(HI); i++)

#define GETINT(x) scanf("%d", &x)
#define GETDBL(x) scanf("%lf", &x)
#define GETSTR(x) scanf("%s", x)
#define NEWINT(x) int x; scanf("%d", &x)
#define NEWDBL(x) double x; scanf("%lf", &x)
#define NEWLN putchar('\n')

typedef long long ll;

const ll MOD = 1000000007;
//const double PI = atan(1) * 4;

#ifdef _WIN32
#define popcnt __popcnt
#else
#define popcnt __builtin_popcount
#endif





const int SZ = 2000333;

ll inv[SZ];
ll fac[SZ];
ll invfac[SZ];

void precalc() {
	inv[1] = 1;
	for (int x=2; x<SZ; x++) {
		ll q = MOD / x;
		ll r = MOD % x;

		q = MOD - q;
		inv[x] = q * inv[r] % MOD;
	}

	fac[0] = 1;
	for (int x=1; x<SZ; x++) fac[x] = fac[x-1] * x % MOD;

	invfac[0] = 1;
	for (int x=1; x<SZ; x++) invfac[x] = invfac[x-1] * inv[x] % MOD;
}

ll getCatalanNumber(int n) {
	return fac[2*n] * invfac[n] % MOD * invfac[n+1] % MOD;
}







int main() {
	precalc();

	int N, K;
	cin >> N >> K;



	ll sum = K;
	ll a = K;
	ll k = K*K%MOD;

	for (int i=2; i<=N; i++) {
		if (i&1) {
			sum = (sum*K%MOD + sum - a + MOD) % MOD;
			a = getCatalanNumber(i/2 + 1) * k % MOD;
			k = k * K % MOD;
		} 
		else {
			sum = (sum*K%MOD + sum) % MOD;
		}
	}


	cout << sum << endl;


	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 116 ms 48604 KB Output is correct
2 Correct 109 ms 48604 KB Output is correct
3 Correct 124 ms 48604 KB Output is correct
4 Correct 112 ms 48604 KB Output is correct
5 Correct 126 ms 48604 KB Output is correct
6 Correct 110 ms 48604 KB Output is correct
7 Correct 114 ms 48604 KB Output is correct
8 Correct 107 ms 48604 KB Output is correct
9 Correct 108 ms 48604 KB Output is correct
10 Correct 113 ms 48604 KB Output is correct
11 Correct 107 ms 48604 KB Output is correct
12 Correct 122 ms 48604 KB Output is correct
13 Correct 123 ms 48604 KB Output is correct
14 Correct 117 ms 48604 KB Output is correct
15 Correct 113 ms 48604 KB Output is correct
16 Correct 110 ms 48604 KB Output is correct
17 Correct 121 ms 48604 KB Output is correct
18 Correct 127 ms 48604 KB Output is correct
19 Correct 123 ms 48604 KB Output is correct
20 Correct 123 ms 48604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 48604 KB Output isn't correct
2 Halted 0 ms 0 KB -