結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー GrenacheGrenache
提出日時 2016-07-08 22:48:04
言語 Java19
(openjdk 21)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 2,098 bytes
コンパイル時間 4,005 ms
コンパイル使用メモリ 75,676 KB
実行使用メモリ 107,668 KB
最終ジャッジ日時 2023-08-03 08:41:37
合計ジャッジ時間 22,280 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
68,680 KB
testcase_01 AC 97 ms
68,760 KB
testcase_02 AC 98 ms
68,520 KB
testcase_03 AC 99 ms
68,428 KB
testcase_04 AC 99 ms
68,532 KB
testcase_05 AC 98 ms
66,424 KB
testcase_06 AC 99 ms
68,460 KB
testcase_07 AC 98 ms
68,364 KB
testcase_08 AC 99 ms
68,276 KB
testcase_09 AC 157 ms
72,312 KB
testcase_10 AC 144 ms
72,520 KB
testcase_11 AC 174 ms
70,112 KB
testcase_12 AC 145 ms
72,800 KB
testcase_13 AC 287 ms
76,352 KB
testcase_14 AC 181 ms
69,880 KB
testcase_15 AC 141 ms
72,596 KB
testcase_16 AC 145 ms
73,096 KB
testcase_17 AC 163 ms
74,644 KB
testcase_18 AC 340 ms
79,268 KB
testcase_19 AC 98 ms
66,984 KB
testcase_20 AC 98 ms
68,912 KB
testcase_21 AC 100 ms
68,588 KB
testcase_22 AC 100 ms
68,444 KB
testcase_23 AC 98 ms
68,496 KB
testcase_24 AC 98 ms
68,772 KB
testcase_25 AC 100 ms
68,580 KB
testcase_26 AC 100 ms
68,380 KB
testcase_27 AC 100 ms
68,536 KB
testcase_28 AC 99 ms
68,608 KB
testcase_29 AC 99 ms
68,436 KB
testcase_30 AC 100 ms
68,848 KB
testcase_31 AC 99 ms
68,436 KB
testcase_32 AC 99 ms
68,384 KB
testcase_33 AC 99 ms
68,568 KB
testcase_34 AC 99 ms
68,628 KB
testcase_35 AC 100 ms
68,596 KB
testcase_36 AC 98 ms
68,404 KB
testcase_37 AC 99 ms
68,568 KB
testcase_38 AC 100 ms
68,380 KB
testcase_39 AC 99 ms
68,604 KB
testcase_40 AC 98 ms
68,576 KB
testcase_41 AC 98 ms
68,764 KB
testcase_42 AC 99 ms
68,496 KB
testcase_43 AC 99 ms
66,416 KB
testcase_44 AC 98 ms
68,456 KB
testcase_45 AC 98 ms
68,564 KB
testcase_46 AC 99 ms
68,400 KB
testcase_47 AC 99 ms
68,460 KB
testcase_48 AC 99 ms
68,584 KB
testcase_49 AC 352 ms
80,120 KB
testcase_50 AC 143 ms
72,592 KB
testcase_51 AC 141 ms
72,168 KB
testcase_52 AC 220 ms
71,820 KB
testcase_53 AC 147 ms
72,868 KB
testcase_54 AC 234 ms
72,024 KB
testcase_55 AC 112 ms
69,664 KB
testcase_56 AC 147 ms
73,080 KB
testcase_57 AC 259 ms
74,096 KB
testcase_58 AC 358 ms
87,544 KB
testcase_59 AC 331 ms
81,116 KB
testcase_60 AC 240 ms
74,096 KB
testcase_61 AC 395 ms
107,668 KB
testcase_62 AC 238 ms
73,748 KB
testcase_63 AC 340 ms
86,960 KB
testcase_64 AC 229 ms
71,920 KB
testcase_65 AC 159 ms
72,436 KB
testcase_66 AC 229 ms
74,272 KB
testcase_67 AC 231 ms
74,372 KB
testcase_68 AC 230 ms
71,992 KB
testcase_69 AC 97 ms
68,528 KB
testcase_70 AC 97 ms
68,540 KB
testcase_71 AC 97 ms
68,376 KB
testcase_72 AC 96 ms
68,248 KB
testcase_73 AC 96 ms
68,452 KB
testcase_74 AC 96 ms
68,340 KB
testcase_75 AC 95 ms
68,424 KB
testcase_76 AC 96 ms
68,428 KB
testcase_77 AC 96 ms
68,376 KB
testcase_78 AC 97 ms
68,468 KB
testcase_79 AC 98 ms
68,428 KB
testcase_80 AC 96 ms
68,460 KB
testcase_81 AC 98 ms
68,432 KB
testcase_82 AC 96 ms
68,420 KB
testcase_83 AC 100 ms
68,244 KB
testcase_84 AC 99 ms
68,392 KB
testcase_85 AC 96 ms
68,404 KB
testcase_86 AC 96 ms
68,380 KB
testcase_87 AC 97 ms
68,516 KB
testcase_88 AC 97 ms
68,604 KB
testcase_89 AC 243 ms
74,180 KB
testcase_90 AC 280 ms
76,184 KB
testcase_91 AC 345 ms
79,792 KB
testcase_92 AC 165 ms
74,236 KB
testcase_93 AC 303 ms
80,148 KB
testcase_94 AC 113 ms
69,468 KB
testcase_95 AC 329 ms
81,912 KB
testcase_96 AC 272 ms
75,224 KB
testcase_97 AC 271 ms
75,236 KB
testcase_98 AC 230 ms
72,456 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