結果

問題 No.503 配列コレクション
ユーザー 37zigen37zigen
提出日時 2017-04-08 03:10:30
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,423 bytes
コンパイル時間 3,634 ms
コンパイル使用メモリ 73,720 KB
実行使用メモリ 105,864 KB
最終ジャッジ日時 2023-09-23 04:17:33
合計ジャッジ時間 11,143 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 290 ms
101,456 KB
testcase_01 AC 295 ms
103,648 KB
testcase_02 AC 291 ms
103,616 KB
testcase_03 AC 291 ms
103,460 KB
testcase_04 RE -
testcase_05 AC 301 ms
103,448 KB
testcase_06 AC 304 ms
103,264 KB
testcase_07 AC 302 ms
103,612 KB
testcase_08 AC 294 ms
103,848 KB
testcase_09 AC 296 ms
103,808 KB
testcase_10 AC 305 ms
103,540 KB
testcase_11 AC 308 ms
103,412 KB
testcase_12 AC 294 ms
103,292 KB
testcase_13 AC 303 ms
103,216 KB
testcase_14 AC 297 ms
103,460 KB
testcase_15 AC 299 ms
103,800 KB
testcase_16 AC 304 ms
103,468 KB
testcase_17 AC 298 ms
103,444 KB
testcase_18 AC 297 ms
103,572 KB
testcase_19 RE -
testcase_20 AC 295 ms
103,272 KB
testcase_21 RE -
testcase_22 AC 283 ms
103,876 KB
testcase_23 AC 294 ms
103,632 KB
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final long mo = 1_000_000_000 + 7;

	void run() {
		long[] fac = new long[2_000_000];
		long[] invfac = new long[fac.length];
		long[] inv = new long[fac.length];
		fac[0] = 1;
		inv[0] = 1;
		inv[1] = 1;
		invfac[0] = 1;
		for (int i = 1; i < fac.length; ++i) {
			fac[i] = fac[i - 1] * i % mo;
		}
		for (int i = 2; i < inv.length; ++i) {
			// 0=p/i*i+p%i
			// i^(-1)=-1*(p/i)*(p%i)^(-1)
			inv[i] = (mo - inv[(int) (mo % i)] * (mo / i) % mo) % mo;
		}
		for (int i = 1; i < invfac.length; ++i) {
			invfac[i] = invfac[i - 1] * inv[i] % mo;
		}
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int D = sc.nextInt();
		int q = N / (K - 1);
		if (N % (K - 1) == 0)
			--q;
		int res = N - q * (K - 1);
		if (D == 1) {
			System.out.println(res);
			return;
		}
		long comb = 0;
		long pow = 1;
		for (int i = 0; i <= q; ++i) {
			comb = comb + pow * H(q - i, res - 1, fac, invfac, mo);
			comb %= mo;
			pow = (pow * D) % mo;
		}
		comb = (comb * res) % mo;
		System.out.println(comb);
	}

	long H(int a, int b, long[] fac, long[] invfac, long mo) {
		// (a+b-1)C(a)
		return fac[a + b - 1] * invfac[a] % mo * invfac[b - 1] % mo;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0