結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー GrenacheGrenache
提出日時 2016-07-08 22:45:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,021 bytes
コンパイル時間 3,525 ms
コンパイル使用メモリ 78,956 KB
実行使用メモリ 102,184 KB
最終ジャッジ日時 2024-04-21 07:26:55
合計ジャッジ時間 22,597 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
67,944 KB
testcase_01 AC 111 ms
54,460 KB
testcase_02 AC 112 ms
54,500 KB
testcase_03 WA -
testcase_04 AC 111 ms
54,364 KB
testcase_05 AC 111 ms
54,548 KB
testcase_06 AC 111 ms
54,656 KB
testcase_07 AC 110 ms
54,376 KB
testcase_08 AC 112 ms
54,380 KB
testcase_09 AC 169 ms
60,540 KB
testcase_10 AC 158 ms
59,324 KB
testcase_11 AC 185 ms
57,748 KB
testcase_12 AC 157 ms
70,568 KB
testcase_13 AC 294 ms
62,432 KB
testcase_14 AC 185 ms
58,024 KB
testcase_15 AC 154 ms
58,056 KB
testcase_16 AC 155 ms
70,176 KB
testcase_17 AC 195 ms
65,664 KB
testcase_18 AC 372 ms
69,112 KB
testcase_19 AC 110 ms
67,860 KB
testcase_20 AC 111 ms
54,564 KB
testcase_21 AC 112 ms
54,496 KB
testcase_22 AC 113 ms
54,556 KB
testcase_23 AC 115 ms
54,616 KB
testcase_24 AC 112 ms
54,388 KB
testcase_25 AC 112 ms
54,688 KB
testcase_26 AC 112 ms
54,364 KB
testcase_27 AC 112 ms
54,516 KB
testcase_28 AC 112 ms
54,344 KB
testcase_29 AC 112 ms
54,376 KB
testcase_30 AC 113 ms
54,480 KB
testcase_31 AC 110 ms
54,428 KB
testcase_32 AC 112 ms
54,612 KB
testcase_33 AC 112 ms
54,608 KB
testcase_34 AC 110 ms
54,368 KB
testcase_35 AC 112 ms
54,540 KB
testcase_36 AC 111 ms
54,400 KB
testcase_37 AC 111 ms
54,512 KB
testcase_38 AC 112 ms
54,732 KB
testcase_39 AC 112 ms
54,716 KB
testcase_40 AC 112 ms
54,604 KB
testcase_41 AC 111 ms
54,680 KB
testcase_42 AC 113 ms
54,692 KB
testcase_43 AC 112 ms
54,300 KB
testcase_44 AC 111 ms
54,600 KB
testcase_45 AC 111 ms
54,528 KB
testcase_46 AC 112 ms
54,508 KB
testcase_47 AC 112 ms
54,324 KB
testcase_48 AC 112 ms
54,640 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 111 ms
54,408 KB
testcase_70 AC 110 ms
54,208 KB
testcase_71 AC 111 ms
54,372 KB
testcase_72 AC 110 ms
54,452 KB
testcase_73 AC 111 ms
54,576 KB
testcase_74 AC 110 ms
54,560 KB
testcase_75 AC 111 ms
54,456 KB
testcase_76 AC 112 ms
54,264 KB
testcase_77 AC 111 ms
54,720 KB
testcase_78 AC 109 ms
54,476 KB
testcase_79 AC 111 ms
54,504 KB
testcase_80 AC 113 ms
54,528 KB
testcase_81 AC 112 ms
54,664 KB
testcase_82 AC 112 ms
54,572 KB
testcase_83 AC 111 ms
54,460 KB
testcase_84 AC 112 ms
54,340 KB
testcase_85 AC 112 ms
54,392 KB
testcase_86 AC 111 ms
54,668 KB
testcase_87 AC 110 ms
54,560 KB
testcase_88 AC 111 ms
54,472 KB
testcase_89 AC 248 ms
61,924 KB
testcase_90 AC 303 ms
73,868 KB
testcase_91 AC 360 ms
69,928 KB
testcase_92 AC 183 ms
72,040 KB
testcase_93 AC 330 ms
66,112 KB
testcase_94 AC 135 ms
68,660 KB
testcase_95 AC 330 ms
65,708 KB
testcase_96 AC 298 ms
72,412 KB
testcase_97 AC 294 ms
62,304 KB
testcase_98 AC 239 ms
70,964 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;
			}

			pr.println(C(m - sum - (k - 1) + k, k));
		} 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