結果

問題 No.1035 Color Box
ユーザー ks2mks2m
提出日時 2020-04-24 22:01:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 852 bytes
コンパイル時間 2,252 ms
コンパイル使用メモリ 77,084 KB
実行使用メモリ 56,212 KB
最終ジャッジ日時 2024-04-23 03:18:38
合計ジャッジ時間 8,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,008 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 131 ms
53,976 KB
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 -
testcase_19 AC 139 ms
54,256 KB
testcase_20 AC 130 ms
54,220 KB
testcase_21 AC 131 ms
53,888 KB
testcase_22 AC 135 ms
54,236 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 129 ms
54,124 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 128 ms
53,816 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		int mod = 1000000007;
		long val1 = nCr(n, n - m, mod);
		long val2 = 1;
		for (int i = 1; i <= m; i++) {
			val2 = val2 * i % mod;
		}
		System.out.println(val1 * val2 % mod);
	}

	static long nCr(int n, int r, int m) {
		long val = 1;
		for (int i = 1; i <= r; i++) {
			val = val * (n - i + 1) % m;
			val = val * modinv(i, m) % m;
		}
		return val;
	}

	static long modinv(long a, int m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}
0