結果

問題 No.462 6日知らずのコンピュータ
ユーザー 37zigen37zigen
提出日時 2016-12-13 12:08:02
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,280 bytes
コンパイル時間 3,259 ms
コンパイル使用メモリ 77,436 KB
実行使用メモリ 42,100 KB
最終ジャッジ日時 2024-05-07 09:16:32
合計ジャッジ時間 17,894 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
41,712 KB
testcase_01 AC 144 ms
41,396 KB
testcase_02 AC 161 ms
41,884 KB
testcase_03 AC 167 ms
41,780 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 146 ms
41,644 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 134 ms
41,048 KB
testcase_50 AC 142 ms
41,480 KB
testcase_51 AC 132 ms
41,128 KB
testcase_52 AC 151 ms
41,776 KB
testcase_53 AC 133 ms
41,348 KB
testcase_54 AC 152 ms
41,716 KB
testcase_55 AC 145 ms
41,412 KB
testcase_56 AC 155 ms
41,520 KB
testcase_57 AC 148 ms
41,756 KB
testcase_58 AC 135 ms
41,184 KB
testcase_59 AC 149 ms
42,100 KB
testcase_60 AC 137 ms
41,336 KB
testcase_61 AC 142 ms
41,600 KB
testcase_62 WA -
testcase_63 AC 153 ms
41,832 KB
testcase_64 AC 136 ms
41,176 KB
testcase_65 AC 129 ms
41,364 KB
testcase_66 AC 156 ms
41,852 KB
testcase_67 AC 154 ms
41,848 KB
testcase_68 AC 148 ms
41,792 KB
testcase_69 AC 138 ms
41,140 KB
testcase_70 AC 146 ms
41,984 KB
testcase_71 AC 137 ms
41,080 KB
testcase_72 AC 149 ms
41,404 KB
testcase_73 AC 151 ms
41,844 KB
testcase_74 AC 130 ms
41,172 KB
testcase_75 AC 157 ms
41,556 KB
testcase_76 AC 139 ms
41,192 KB
testcase_77 AC 155 ms
41,976 KB
testcase_78 AC 149 ms
41,352 KB
testcase_79 AC 143 ms
41,392 KB
testcase_80 AC 148 ms
41,848 KB
testcase_81 AC 146 ms
41,468 KB
testcase_82 AC 142 ms
42,028 KB
testcase_83 AC 142 ms
41,432 KB
testcase_84 AC 134 ms
41,144 KB
testcase_85 AC 136 ms
41,308 KB
testcase_86 AC 134 ms
41,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q462 {

	final static long MODULO = 1_000_000_000 + 7;

	public static void main(String[] args) {
		long[] fac = new long[100];
		long[] invfac = new long[100];
		fac[0] = 1;
		for (int i = 1; i < 100; ++i) {
			fac[i] = fac[i - 1] * i % MODULO;
		}
		invfac[invfac.length - 1] = pow(fac[fac.length - 1], MODULO - 2);
		for (int i = invfac.length - 2; i >= 0; --i) {
			invfac[i] = invfac[i + 1] * (i + 1) % MODULO;
		}

		long[][] dp = new long[100][];
		// dp[i][j]:i個からj個数を作る方法
		for (int i = 0; i < 100; ++i) {
			dp[i] = new long[i + 1];
			dp[i][0] = 1;
			for (int j = 1; j <= i; ++j) {
				for (int k = 1; k <= j; ++k) {
					dp[i][j] += dp[i][j - k] * fac[i - j + k] % MODULO * invfac[k] % MODULO * invfac[i - j] % MODULO;
					dp[i][j] %= MODULO;
				}
			}
		}
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if (k == 0) {
			System.out.println(fac[n] % MODULO);
			return;
		}
		long[] a = new long[k];
		long[] diff = new long[k + 1];
		for (int i = 0; i < k; ++i) {
			a[i] = sc.nextLong();
		}
		for (int i = 0; i + 1 < k; ++i) {
			diff[i + 1] = count(a[i], a[i + 1]);
			if (diff[i + 1] < 0) {
				System.out.println(0);
				return;
			}
		}
		diff[0] = count(0, a[0]);
		diff[k] = count(a[k - 1], (1L << n) - 1);
		long[] dp1 = new long[n + 1];
		dp1[0] = 1;
		if (a[0] != 0)
			dp1[1] = 1;
		for (int i = 0; i < k + 1; ++i) {
			for (int j = n; j >= 1; --j) {
				boolean f = false;
				if ((a[k - 1] != (1L << n) - 1 && i == k))
					f = true;
				for (int l = 1; l <= diff[i] + (f ? 0 : -1) && j - l >= 0; ++l) {
					dp1[j] += dp1[j - l] * dp[(int) diff[i]][l] % MODULO;
					dp1[j] %= MODULO;
				}
			}
		}
		System.out.println(dp1[n + 1 - k]);
	}

	static long count(long min, long max) {
		for (int i = 0; i < 60; ++i) {
			if ((min & (1 << i)) > 0 && (max & (1 << i)) == 0) {
				return -1;
			}
		}
		int diff = Long.bitCount(max) - Long.bitCount(min);
		return diff;
	}

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

	static long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = (a * a) % MODULO) {
			if (n % 2 == 1)
				ret = (ret * a) % MODULO;
		}
		return ret;
	}
}
0