結果

問題 No.314 ケンケンパ
ユーザー cherrypi59cherrypi59
提出日時 2018-07-07 20:09:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 901 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 52,580 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2023-09-18 14:47:46
合計ジャッジ時間 1,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
19,056 KB
testcase_01 AC 18 ms
18,988 KB
testcase_02 AC 18 ms
18,872 KB
testcase_03 AC 18 ms
19,056 KB
testcase_04 AC 18 ms
19,048 KB
testcase_05 AC 18 ms
18,988 KB
testcase_06 AC 18 ms
18,884 KB
testcase_07 AC 18 ms
19,064 KB
testcase_08 AC 18 ms
19,060 KB
testcase_09 AC 18 ms
18,888 KB
testcase_10 AC 19 ms
19,068 KB
testcase_11 AC 18 ms
18,948 KB
testcase_12 AC 18 ms
18,932 KB
testcase_13 AC 19 ms
18,992 KB
testcase_14 AC 18 ms
18,884 KB
testcase_15 AC 18 ms
18,992 KB
testcase_16 AC 18 ms
19,072 KB
testcase_17 AC 19 ms
18,940 KB
testcase_18 AC 20 ms
18,888 KB
testcase_19 AC 23 ms
18,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#define M 1000000007
#define MAX_N 1000000
using namespace std;
typedef long long ll;

ll fact_n[MAX_N + 1], fact_inv[MAX_N + 1];

ll mod_pow(ll a, ll n) {
	ll x = 1;
	while (n > 0) {
		if (n & 1) x = x * a % M;
		a = a * a % M;
		n >>= 1;
	}
	return x;
}


ll combination(int n, int r) {
	if (n == 0 && r == 0) return 1;
	else if (n < r || n < 0) return 0;

	ll com = fact_n[n] * fact_inv[r] % M;
	return com * fact_inv[n - r] % M;
}



int main()
{
	int n, j;
	ll com = 0;
	cin >> n;

	fact_n[0] = fact_inv[0] = 1;
	for (int i = 1;i <= MAX_N;i++) fact_n[i] = fact_n[i - 1] * i % M;

	fact_inv[MAX_N] = mod_pow(fact_n[MAX_N], M - 2);
	for (int i = MAX_N - 1;i > 0;i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % M;

	for (int i = 0;i <= n;i++) {
		if (n - 2 * i >= 0) {
			j = (n - 2 * i) / 3;
			com += combination(i + j, i) % M;
		}
	}

	cout << com % M << endl;
    return 0;
}

0