結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
18,880 KB
testcase_01 AC 139 ms
18,980 KB
testcase_02 AC 139 ms
19,016 KB
testcase_03 AC 139 ms
19,124 KB
testcase_04 AC 139 ms
19,060 KB
testcase_05 AC 139 ms
18,964 KB
testcase_06 AC 139 ms
18,880 KB
testcase_07 AC 139 ms
18,884 KB
testcase_08 AC 140 ms
19,056 KB
testcase_09 AC 139 ms
18,988 KB
testcase_10 AC 140 ms
19,028 KB
testcase_11 AC 138 ms
19,124 KB
testcase_12 AC 139 ms
18,964 KB
testcase_13 AC 140 ms
19,220 KB
testcase_14 AC 139 ms
19,128 KB
testcase_15 AC 139 ms
19,004 KB
testcase_16 AC 140 ms
18,876 KB
testcase_17 AC 140 ms
19,084 KB
testcase_18 AC 141 ms
19,136 KB
testcase_19 AC 144 ms
18,868 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[i] = mod_pow(fact_n[i], M - 2);
	}

	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