結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー GrenacheGrenache
提出日時 2016-07-08 22:48:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 2,098 bytes
コンパイル時間 3,267 ms
コンパイル使用メモリ 78,616 KB
実行使用メモリ 91,676 KB
最終ジャッジ日時 2024-04-21 07:28:21
合計ジャッジ時間 20,903 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
54,248 KB
testcase_01 AC 107 ms
54,316 KB
testcase_02 AC 103 ms
54,684 KB
testcase_03 AC 104 ms
54,196 KB
testcase_04 AC 105 ms
54,496 KB
testcase_05 AC 107 ms
54,264 KB
testcase_06 AC 103 ms
54,380 KB
testcase_07 AC 102 ms
54,252 KB
testcase_08 AC 103 ms
54,236 KB
testcase_09 AC 158 ms
60,960 KB
testcase_10 AC 151 ms
59,316 KB
testcase_11 AC 175 ms
57,720 KB
testcase_12 AC 154 ms
59,144 KB
testcase_13 AC 269 ms
62,652 KB
testcase_14 AC 176 ms
58,120 KB
testcase_15 AC 145 ms
58,104 KB
testcase_16 AC 155 ms
59,400 KB
testcase_17 AC 184 ms
65,652 KB
testcase_18 AC 332 ms
69,360 KB
testcase_19 AC 104 ms
54,408 KB
testcase_20 AC 115 ms
54,220 KB
testcase_21 AC 116 ms
54,656 KB
testcase_22 AC 104 ms
54,220 KB
testcase_23 AC 102 ms
54,236 KB
testcase_24 AC 102 ms
54,388 KB
testcase_25 AC 102 ms
54,592 KB
testcase_26 AC 104 ms
54,380 KB
testcase_27 AC 103 ms
54,508 KB
testcase_28 AC 103 ms
54,216 KB
testcase_29 AC 105 ms
54,488 KB
testcase_30 AC 108 ms
54,496 KB
testcase_31 AC 104 ms
54,424 KB
testcase_32 AC 101 ms
54,360 KB
testcase_33 AC 101 ms
54,364 KB
testcase_34 AC 105 ms
54,516 KB
testcase_35 AC 104 ms
54,520 KB
testcase_36 AC 103 ms
54,548 KB
testcase_37 AC 106 ms
54,220 KB
testcase_38 AC 104 ms
54,476 KB
testcase_39 AC 107 ms
54,264 KB
testcase_40 AC 103 ms
54,432 KB
testcase_41 AC 102 ms
54,208 KB
testcase_42 AC 103 ms
54,340 KB
testcase_43 AC 104 ms
54,208 KB
testcase_44 AC 103 ms
54,440 KB
testcase_45 AC 102 ms
54,528 KB
testcase_46 AC 109 ms
54,228 KB
testcase_47 AC 106 ms
54,244 KB
testcase_48 AC 104 ms
54,332 KB
testcase_49 AC 341 ms
68,660 KB
testcase_50 AC 148 ms
58,012 KB
testcase_51 AC 156 ms
57,596 KB
testcase_52 AC 188 ms
57,928 KB
testcase_53 AC 151 ms
59,552 KB
testcase_54 AC 225 ms
61,472 KB
testcase_55 AC 119 ms
55,112 KB
testcase_56 AC 147 ms
59,224 KB
testcase_57 AC 247 ms
61,248 KB
testcase_58 AC 362 ms
75,796 KB
testcase_59 AC 313 ms
65,440 KB
testcase_60 AC 207 ms
60,100 KB
testcase_61 AC 395 ms
91,676 KB
testcase_62 AC 231 ms
61,624 KB
testcase_63 AC 371 ms
76,772 KB
testcase_64 AC 197 ms
60,428 KB
testcase_65 AC 165 ms
62,080 KB
testcase_66 AC 211 ms
60,504 KB
testcase_67 AC 198 ms
60,652 KB
testcase_68 AC 209 ms
59,976 KB
testcase_69 AC 104 ms
54,488 KB
testcase_70 AC 105 ms
54,188 KB
testcase_71 AC 105 ms
54,440 KB
testcase_72 AC 103 ms
54,332 KB
testcase_73 AC 102 ms
54,208 KB
testcase_74 AC 104 ms
54,380 KB
testcase_75 AC 105 ms
54,316 KB
testcase_76 AC 106 ms
54,644 KB
testcase_77 AC 106 ms
54,356 KB
testcase_78 AC 105 ms
54,440 KB
testcase_79 AC 106 ms
54,220 KB
testcase_80 AC 107 ms
54,548 KB
testcase_81 AC 105 ms
54,548 KB
testcase_82 AC 107 ms
54,516 KB
testcase_83 AC 107 ms
54,376 KB
testcase_84 AC 107 ms
54,520 KB
testcase_85 AC 104 ms
54,372 KB
testcase_86 AC 105 ms
54,528 KB
testcase_87 AC 107 ms
54,512 KB
testcase_88 AC 106 ms
54,404 KB
testcase_89 AC 235 ms
61,540 KB
testcase_90 AC 286 ms
63,888 KB
testcase_91 AC 346 ms
70,192 KB
testcase_92 AC 171 ms
61,916 KB
testcase_93 AC 324 ms
66,116 KB
testcase_94 AC 124 ms
55,664 KB
testcase_95 AC 319 ms
65,700 KB
testcase_96 AC 275 ms
62,680 KB
testcase_97 AC 272 ms
62,836 KB
testcase_98 AC 199 ms
60,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder389 {

    public static void main(String[] args) {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    	Printer pr = new Printer(System.out);

		try {
			int m = Integer.parseInt(br.readLine());
			List<Integer> h = new ArrayList<>();
			int sum = 0;
			for (String s : br.readLine().split(" ")) {
				int tmp = Integer.parseInt(s);
				h.add(tmp);
				sum += tmp;
			}

			preCombi2(1_000_000);

			int k = h.size();
			if (sum == 0) {
				k = 0;
			}

			int ret = C(m - sum - (k - 1) + k, k);
			if (ret == 0) {
				pr.println("NA");
			} else {
				pr.println(ret);
			}
		} catch (NumberFormatException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

        pr.close();
    }

	private static int MOD = 1_000_000_007;
	private static long[] fact;
	private static long[] ifact;

	private static void preCombi2(int size) {
		// cache size need size * 2 * 16.
		fact = new long[size + 1];
		fact[0] = 1;
		for (int i = 1; i <= size; i++) {
			fact[i] = fact[i - 1] * i % MOD;
		}

		ifact = new long[size + 1];
		ifact[0] = 1;

		int loop = MOD - 2;
		long x = fact[size];
		ifact[size] = 1;
		while (loop > 0) {
			if (loop % 2 == 1) {
				ifact[size] = ifact[size] * x % MOD;
			}
			x = x * x % MOD;
			loop /= 2;
		}

		for (int i = size - 1; i >= 0; i--) {
			ifact[i] = ifact[i + 1] * (i + 1) % MOD;
		}
	}

	private static int C(int n, int r) {
		if (r > n) {
			return 0;
		}

		return (int)(((fact[n] * ifact[n - r]) % MOD) * ifact[r] % MOD);
	}

	@SuppressWarnings("unused")
	private static int P(int n, int r) {
		if (r > n) {
			return 0;
		}

		return (int)((fact[n] * ifact[n -r]) % MOD);
	}

	@SuppressWarnings("unused")
	private static int H(int n, int r) {
		if (n == 0 && r == 0) {
			return 1;
		}

		return C(n + r - 1, r);
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0