結果

問題 No.665 Bernoulli Bernoulli
ユーザー snrnsidysnrnsidy
提出日時 2021-10-22 20:24:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 831 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 45,136 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 10:04:10
合計ジャッジ時間 9,825 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 554 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
using namespace std;
int const MOD = 1000000007;
int const K_MAX = 10000;
int mul_inv(int a, int b) {
	int b0 = b, t, q;
	int x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}
int main() {
	long long int N, K;
	long long int _aa[2][K_MAX], *alt1 = _aa[0], *alt2 = _aa[1];
	scanf("%lld %lld", &N, &K);
	alt1[0] = 1LL * N*(N+1)/2 % MOD;
	for(int i=1; i+1<=K; ++i) {
		alt2[0] = N;
		for(int j=1; j<=i+1; ++j) {
			alt2[0] = 1LL * alt2[0]*(N+j) % MOD;
		}
		alt2[0] = 1LL * alt2[0]*mul_inv(i+2, MOD) % MOD;
		for(int j=1; j<i+1; ++j) {
			alt2[j] = (alt2[j-1] - 1LL * alt1[j-1]*(i+1-j) % MOD + MOD) % MOD;
		}
		swap(alt1, alt2);
	}
	printf("%lld", alt1[K-1]);
	return 0;
}
0