답안 #20175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20175 2016-03-01T06:31:00 Z sui 괄호 (kriii4_R) C++14
100 / 100
67 ms 17352 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 = 1000333;

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

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;
	ll K;
	cin >> N >> K;



	ll sum = 1;
	ll k = 1;

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

			k = k * K % MOD;
		} 
		else {
			sum = (K + 1) * sum % MOD;
		}
	}



	cout << sum << endl;


	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 17352 KB Output is correct
2 Correct 54 ms 17352 KB Output is correct
3 Correct 63 ms 17352 KB Output is correct
4 Correct 60 ms 17352 KB Output is correct
5 Correct 64 ms 17352 KB Output is correct
6 Correct 56 ms 17352 KB Output is correct
7 Correct 57 ms 17352 KB Output is correct
8 Correct 57 ms 17352 KB Output is correct
9 Correct 51 ms 17352 KB Output is correct
10 Correct 53 ms 17352 KB Output is correct
11 Correct 56 ms 17352 KB Output is correct
12 Correct 63 ms 17352 KB Output is correct
13 Correct 62 ms 17352 KB Output is correct
14 Correct 57 ms 17352 KB Output is correct
15 Correct 57 ms 17352 KB Output is correct
16 Correct 51 ms 17352 KB Output is correct
17 Correct 62 ms 17352 KB Output is correct
18 Correct 65 ms 17352 KB Output is correct
19 Correct 62 ms 17352 KB Output is correct
20 Correct 58 ms 17352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 17352 KB Output is correct
2 Correct 55 ms 17352 KB Output is correct
3 Correct 51 ms 17352 KB Output is correct
4 Correct 61 ms 17352 KB Output is correct
5 Correct 61 ms 17352 KB Output is correct
6 Correct 63 ms 17352 KB Output is correct
7 Correct 61 ms 17352 KB Output is correct
8 Correct 49 ms 17352 KB Output is correct
9 Correct 57 ms 17352 KB Output is correct
10 Correct 43 ms 17352 KB Output is correct
11 Correct 56 ms 17352 KB Output is correct
12 Correct 56 ms 17352 KB Output is correct
13 Correct 64 ms 17352 KB Output is correct
14 Correct 50 ms 17352 KB Output is correct
15 Correct 51 ms 17352 KB Output is correct
16 Correct 62 ms 17352 KB Output is correct
17 Correct 54 ms 17352 KB Output is correct
18 Correct 63 ms 17352 KB Output is correct
19 Correct 67 ms 17352 KB Output is correct
20 Correct 63 ms 17352 KB Output is correct