結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 37zigen37zigen
提出日時 2016-07-07 20:41:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 493 ms / 2,000 ms
コード長 1,309 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 79,276 KB
実行使用メモリ 87,260 KB
最終ジャッジ日時 2024-04-21 00:59:06
合計ジャッジ時間 25,547 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
41,512 KB
testcase_01 AC 109 ms
40,040 KB
testcase_02 AC 118 ms
41,116 KB
testcase_03 AC 109 ms
40,088 KB
testcase_04 AC 133 ms
41,560 KB
testcase_05 AC 115 ms
40,740 KB
testcase_06 AC 110 ms
40,140 KB
testcase_07 AC 120 ms
41,144 KB
testcase_08 AC 118 ms
41,192 KB
testcase_09 AC 260 ms
48,092 KB
testcase_10 AC 209 ms
44,380 KB
testcase_11 AC 271 ms
48,144 KB
testcase_12 AC 203 ms
44,784 KB
testcase_13 AC 405 ms
58,112 KB
testcase_14 AC 242 ms
48,468 KB
testcase_15 AC 204 ms
44,376 KB
testcase_16 AC 219 ms
44,656 KB
testcase_17 AC 258 ms
48,124 KB
testcase_18 AC 462 ms
71,696 KB
testcase_19 AC 124 ms
41,540 KB
testcase_20 AC 119 ms
41,312 KB
testcase_21 AC 109 ms
39,956 KB
testcase_22 AC 120 ms
41,452 KB
testcase_23 AC 117 ms
40,808 KB
testcase_24 AC 124 ms
41,180 KB
testcase_25 AC 121 ms
40,868 KB
testcase_26 AC 125 ms
41,136 KB
testcase_27 AC 122 ms
41,356 KB
testcase_28 AC 107 ms
40,272 KB
testcase_29 AC 128 ms
40,180 KB
testcase_30 AC 128 ms
41,480 KB
testcase_31 AC 132 ms
41,544 KB
testcase_32 AC 132 ms
41,304 KB
testcase_33 AC 127 ms
40,924 KB
testcase_34 AC 127 ms
41,436 KB
testcase_35 AC 109 ms
40,136 KB
testcase_36 AC 121 ms
41,204 KB
testcase_37 AC 116 ms
41,256 KB
testcase_38 AC 122 ms
41,552 KB
testcase_39 AC 109 ms
40,320 KB
testcase_40 AC 116 ms
41,280 KB
testcase_41 AC 120 ms
41,448 KB
testcase_42 AC 119 ms
41,232 KB
testcase_43 AC 110 ms
40,176 KB
testcase_44 AC 110 ms
40,300 KB
testcase_45 AC 119 ms
41,160 KB
testcase_46 AC 111 ms
40,192 KB
testcase_47 AC 109 ms
40,044 KB
testcase_48 AC 109 ms
40,272 KB
testcase_49 AC 447 ms
71,140 KB
testcase_50 AC 194 ms
43,924 KB
testcase_51 AC 180 ms
43,552 KB
testcase_52 AC 262 ms
47,536 KB
testcase_53 AC 205 ms
45,428 KB
testcase_54 AC 293 ms
50,132 KB
testcase_55 AC 140 ms
41,460 KB
testcase_56 AC 191 ms
45,008 KB
testcase_57 AC 367 ms
57,096 KB
testcase_58 AC 489 ms
70,784 KB
testcase_59 AC 414 ms
60,752 KB
testcase_60 AC 281 ms
51,480 KB
testcase_61 AC 476 ms
87,260 KB
testcase_62 AC 296 ms
51,488 KB
testcase_63 AC 493 ms
71,572 KB
testcase_64 AC 277 ms
47,848 KB
testcase_65 AC 228 ms
48,628 KB
testcase_66 AC 291 ms
51,244 KB
testcase_67 AC 289 ms
50,940 KB
testcase_68 AC 299 ms
50,456 KB
testcase_69 AC 130 ms
41,452 KB
testcase_70 AC 131 ms
41,360 KB
testcase_71 AC 114 ms
40,328 KB
testcase_72 AC 128 ms
41,268 KB
testcase_73 AC 118 ms
40,288 KB
testcase_74 AC 136 ms
41,304 KB
testcase_75 AC 120 ms
40,504 KB
testcase_76 AC 109 ms
40,188 KB
testcase_77 AC 133 ms
41,712 KB
testcase_78 AC 111 ms
40,156 KB
testcase_79 AC 119 ms
41,152 KB
testcase_80 AC 109 ms
39,852 KB
testcase_81 AC 119 ms
41,632 KB
testcase_82 AC 111 ms
40,084 KB
testcase_83 AC 108 ms
40,144 KB
testcase_84 AC 107 ms
40,168 KB
testcase_85 AC 113 ms
40,408 KB
testcase_86 AC 105 ms
40,264 KB
testcase_87 AC 117 ms
41,404 KB
testcase_88 AC 111 ms
40,720 KB
testcase_89 AC 302 ms
54,088 KB
testcase_90 AC 406 ms
60,160 KB
testcase_91 AC 480 ms
70,968 KB
testcase_92 AC 241 ms
48,040 KB
testcase_93 AC 404 ms
60,104 KB
testcase_94 AC 164 ms
41,448 KB
testcase_95 AC 411 ms
60,644 KB
testcase_96 AC 387 ms
58,524 KB
testcase_97 AC 376 ms
56,740 KB
testcase_98 AC 292 ms
50,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) {
		solver();
	}

	final static long MOD = 1_000_000_007;

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int m = Integer.parseInt(sc.nextLine());
		String[] s = sc.nextLine().split(" ");
		int[] num = new int[s.length];
		int res = m;
		for (int i = 0; i < s.length; i++) {
			num[i] = new Integer(s[i]);
			res -= num[i];
		}
		if (num[0] == 0) {
			System.out.println(1);
			return;
		}
		int n = num.length;

		res -= n - 1;
		if (res >= 0) {
			System.out.println(nCk(res + n , res));
		} else {
			System.out.println("NA");
		}
	}

	static long nCk(int n, int k) {
		if (n < k)
			return 0;
		else {
			return (fact(n) % MOD * inv(fact(n - k), MOD) % MOD * inv(fact(k), MOD) % MOD);
		}
	}

	static long fact(int n) {
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= MOD;
		}
		return ans;
	}

	static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	static long inv(long a, long mod) {
		a = a % mod;
		long b = mod;
		long p = 1, q = 0;

		while (b > 1) {
			long c = b / a;
			b = b % a;
			q = q - p * c;
			long d = b;
			b = a;
			a = d;
			d = p;
			p = q;
			q = d;
		}
		while (q < 0)
			q += mod;
		return q;
	}
}
0