結果

問題 No.503 配列コレクション
ユーザー square1001square1001
提出日時 2018-04-17 21:21:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 732 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 64,760 KB
実行使用メモリ 27,104 KB
最終ジャッジ日時 2023-09-09 11:08:19
合計ジャッジ時間 4,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
26,740 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
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 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int N, K, D, fact[2000009], inv[2000009], finv[2000009], lim = 2000000, mod = 1000000007;
int main() {
	cin >> N >> K >> D;
	int P = N / (K - 1), Q = N % (K - 1);
	if (Q == 0) Q += K - 1, P++;
	if (D == 1) cout << Q << endl;
	else {
		fact[0] = 1, finv[0] = 1;
		for (int i = 1; i <= lim; i++) {
			fact[i] = 1LL * fact[i - 1] * i % mod;
			inv[i] = (i == 1 ? 1 : 1LL * inv[mod % i] * (mod - mod / i) % mod);
			finv[i] = 1LL * finv[i - 1] * inv[i] % mod;
		}
		int ret = 0, pw = 1;
		for (int i = 0; i <= Q; i++) {
			ret = (ret + 1LL * pw * fact[P + Q - i - 2] % mod * finv[P - 2] % mod * finv[Q - i]) % mod;
			pw = 1LL * pw * D % mod;
		}
		cout << 1LL * ret * Q << endl;
	}
	return 0;
}
0