結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー hiromi_ayasehiromi_ayase
提出日時 2016-07-08 22:41:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 621 ms / 2,000 ms
コード長 1,249 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 77,040 KB
実行使用メモリ 83,564 KB
最終ジャッジ日時 2024-04-21 07:22:42
合計ジャッジ時間 25,209 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
53,108 KB
testcase_01 AC 128 ms
53,956 KB
testcase_02 AC 125 ms
53,860 KB
testcase_03 AC 125 ms
54,148 KB
testcase_04 AC 129 ms
54,116 KB
testcase_05 AC 124 ms
53,832 KB
testcase_06 AC 128 ms
53,652 KB
testcase_07 AC 127 ms
54,156 KB
testcase_08 AC 128 ms
53,996 KB
testcase_09 AC 258 ms
57,784 KB
testcase_10 AC 231 ms
57,440 KB
testcase_11 AC 269 ms
57,732 KB
testcase_12 AC 227 ms
57,328 KB
testcase_13 AC 438 ms
68,244 KB
testcase_14 AC 276 ms
57,664 KB
testcase_15 AC 216 ms
56,912 KB
testcase_16 AC 217 ms
57,728 KB
testcase_17 AC 273 ms
57,884 KB
testcase_18 AC 621 ms
81,204 KB
testcase_19 AC 130 ms
53,720 KB
testcase_20 AC 128 ms
54,076 KB
testcase_21 AC 128 ms
53,740 KB
testcase_22 AC 126 ms
53,860 KB
testcase_23 AC 128 ms
53,668 KB
testcase_24 AC 129 ms
53,992 KB
testcase_25 AC 130 ms
53,976 KB
testcase_26 AC 133 ms
53,888 KB
testcase_27 AC 130 ms
54,020 KB
testcase_28 AC 129 ms
54,200 KB
testcase_29 AC 126 ms
54,120 KB
testcase_30 AC 115 ms
52,752 KB
testcase_31 AC 129 ms
54,096 KB
testcase_32 AC 127 ms
53,852 KB
testcase_33 AC 125 ms
53,736 KB
testcase_34 AC 130 ms
53,996 KB
testcase_35 AC 131 ms
53,860 KB
testcase_36 AC 126 ms
54,392 KB
testcase_37 AC 117 ms
53,880 KB
testcase_38 AC 113 ms
53,364 KB
testcase_39 AC 129 ms
53,700 KB
testcase_40 AC 128 ms
53,904 KB
testcase_41 AC 112 ms
52,708 KB
testcase_42 AC 129 ms
53,776 KB
testcase_43 AC 127 ms
54,120 KB
testcase_44 AC 127 ms
53,788 KB
testcase_45 AC 127 ms
53,980 KB
testcase_46 AC 130 ms
54,072 KB
testcase_47 AC 129 ms
53,880 KB
testcase_48 AC 130 ms
53,784 KB
testcase_49 AC 503 ms
80,652 KB
testcase_50 AC 205 ms
56,748 KB
testcase_51 AC 189 ms
56,544 KB
testcase_52 AC 277 ms
57,364 KB
testcase_53 AC 214 ms
57,184 KB
testcase_54 AC 278 ms
58,652 KB
testcase_55 AC 159 ms
54,124 KB
testcase_56 AC 201 ms
55,388 KB
testcase_57 AC 332 ms
64,028 KB
testcase_58 AC 446 ms
73,844 KB
testcase_59 AC 428 ms
69,064 KB
testcase_60 AC 291 ms
60,896 KB
testcase_61 AC 492 ms
83,564 KB
testcase_62 AC 303 ms
61,820 KB
testcase_63 AC 409 ms
73,972 KB
testcase_64 AC 280 ms
57,516 KB
testcase_65 AC 240 ms
57,680 KB
testcase_66 AC 295 ms
60,908 KB
testcase_67 AC 283 ms
57,024 KB
testcase_68 AC 281 ms
57,256 KB
testcase_69 AC 128 ms
53,780 KB
testcase_70 AC 126 ms
54,048 KB
testcase_71 AC 131 ms
53,944 KB
testcase_72 AC 127 ms
53,744 KB
testcase_73 AC 127 ms
54,020 KB
testcase_74 AC 125 ms
53,756 KB
testcase_75 AC 127 ms
53,476 KB
testcase_76 AC 124 ms
54,064 KB
testcase_77 AC 128 ms
53,844 KB
testcase_78 AC 128 ms
53,756 KB
testcase_79 AC 129 ms
53,644 KB
testcase_80 AC 126 ms
53,560 KB
testcase_81 AC 126 ms
53,988 KB
testcase_82 AC 129 ms
54,004 KB
testcase_83 AC 126 ms
54,020 KB
testcase_84 AC 126 ms
54,000 KB
testcase_85 AC 128 ms
53,800 KB
testcase_86 AC 130 ms
53,684 KB
testcase_87 AC 128 ms
53,980 KB
testcase_88 AC 128 ms
54,024 KB
testcase_89 AC 349 ms
62,144 KB
testcase_90 AC 447 ms
68,428 KB
testcase_91 AC 591 ms
80,260 KB
testcase_92 AC 271 ms
58,036 KB
testcase_93 AC 485 ms
73,416 KB
testcase_94 AC 171 ms
54,040 KB
testcase_95 AC 455 ms
68,608 KB
testcase_96 AC 448 ms
68,568 KB
testcase_97 AC 422 ms
65,584 KB
testcase_98 AC 325 ms
57,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		String[] s = sc.nextLine().split(" ");
		int K = s.length;
		int[] H = new int[K];
		for (int i = 0; i < K; i++) {
			H[i] = Integer.parseInt(s[i]);
			N -= H[i];
		}
		N++;

		if (H[0] == 0) {
			System.out.println(1);
		} else if (N < K || K < 0 || N <= 0) {
			System.out.println("NA");
		} else {
			System.out.println(combMod(N, K, 1000000007));
		}
	}

	public static long combMod(long n, long r, long mod) {
		long comb = 1;
		for (int i = 0; i < r; i++) {
			comb = (comb * (n - i)) % mod;
			comb = (comb * inverse(r - i, mod)) % mod;
		}
		return comb;
	}

	public static long[] extgcd(long a, long b) {
		long u = 1;
		long v = 0;
		long x = 0;
		long y = 1;

		while (a > 0) {
			long q = b / a;
			x -= q * u;
			y -= q * v;
			b -= q * a;

			long tmp;
			tmp = x;
			x = u;
			u = tmp;
			tmp = y;
			y = v;
			v = tmp;
			tmp = b;
			b = a;
			a = tmp;
		}

		return new long[] { b, x, y };
	}

	public static long inverse(long n, long mod) {
		long[] gcd = extgcd(n, mod);
		if (gcd[0] == 1) {
			return (gcd[1] + mod) % mod;
		} else {
			return 0;
		}
	}
}
0