結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー hiromi_ayasehiromi_ayase
提出日時 2016-07-08 22:39:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,240 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 77,748 KB
実行使用メモリ 83,756 KB
最終ジャッジ日時 2024-04-21 06:04:20
合計ジャッジ時間 26,285 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
41,068 KB
testcase_01 AC 125 ms
40,916 KB
testcase_02 AC 127 ms
41,108 KB
testcase_03 WA -
testcase_04 AC 124 ms
41,076 KB
testcase_05 AC 128 ms
41,076 KB
testcase_06 AC 127 ms
41,068 KB
testcase_07 AC 127 ms
40,852 KB
testcase_08 AC 131 ms
40,984 KB
testcase_09 AC 256 ms
47,972 KB
testcase_10 AC 222 ms
47,108 KB
testcase_11 AC 267 ms
48,164 KB
testcase_12 AC 236 ms
47,372 KB
testcase_13 AC 419 ms
58,092 KB
testcase_14 AC 285 ms
49,712 KB
testcase_15 AC 212 ms
44,200 KB
testcase_16 AC 222 ms
46,964 KB
testcase_17 AC 264 ms
48,212 KB
testcase_18 AC 567 ms
71,304 KB
testcase_19 AC 128 ms
40,888 KB
testcase_20 AC 126 ms
41,260 KB
testcase_21 AC 129 ms
40,952 KB
testcase_22 AC 118 ms
40,032 KB
testcase_23 AC 125 ms
40,824 KB
testcase_24 AC 127 ms
40,792 KB
testcase_25 AC 132 ms
41,128 KB
testcase_26 AC 128 ms
41,168 KB
testcase_27 AC 130 ms
40,672 KB
testcase_28 AC 131 ms
41,136 KB
testcase_29 AC 126 ms
41,040 KB
testcase_30 AC 126 ms
40,960 KB
testcase_31 AC 128 ms
40,576 KB
testcase_32 AC 127 ms
40,976 KB
testcase_33 AC 126 ms
40,944 KB
testcase_34 AC 114 ms
39,660 KB
testcase_35 AC 127 ms
40,944 KB
testcase_36 AC 125 ms
40,944 KB
testcase_37 AC 112 ms
40,128 KB
testcase_38 AC 111 ms
39,900 KB
testcase_39 AC 114 ms
40,024 KB
testcase_40 AC 128 ms
41,068 KB
testcase_41 AC 128 ms
41,236 KB
testcase_42 AC 126 ms
40,876 KB
testcase_43 AC 127 ms
40,864 KB
testcase_44 AC 130 ms
40,832 KB
testcase_45 AC 128 ms
40,972 KB
testcase_46 AC 129 ms
41,160 KB
testcase_47 AC 126 ms
40,848 KB
testcase_48 AC 126 ms
40,832 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 AC 125 ms
40,864 KB
testcase_70 AC 123 ms
40,884 KB
testcase_71 AC 126 ms
41,284 KB
testcase_72 AC 127 ms
41,184 KB
testcase_73 AC 128 ms
41,184 KB
testcase_74 AC 121 ms
40,036 KB
testcase_75 AC 127 ms
40,912 KB
testcase_76 AC 125 ms
40,824 KB
testcase_77 AC 126 ms
41,076 KB
testcase_78 AC 112 ms
39,988 KB
testcase_79 AC 127 ms
41,288 KB
testcase_80 AC 127 ms
40,884 KB
testcase_81 AC 125 ms
41,164 KB
testcase_82 AC 129 ms
40,904 KB
testcase_83 AC 118 ms
39,876 KB
testcase_84 AC 127 ms
40,724 KB
testcase_85 AC 105 ms
39,180 KB
testcase_86 AC 125 ms
40,996 KB
testcase_87 AC 126 ms
41,008 KB
testcase_88 AC 126 ms
40,856 KB
testcase_89 AC 323 ms
52,920 KB
testcase_90 AC 462 ms
58,960 KB
testcase_91 AC 593 ms
70,664 KB
testcase_92 AC 261 ms
48,004 KB
testcase_93 AC 474 ms
60,404 KB
testcase_94 AC 154 ms
41,008 KB
testcase_95 AC 472 ms
59,668 KB
testcase_96 AC 439 ms
58,396 KB
testcase_97 AC 410 ms
55,832 KB
testcase_98 AC 316 ms
47,752 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 (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