結果

問題 No.462 6日知らずのコンピュータ
ユーザー 37zigen37zigen
提出日時 2016-12-13 19:03:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 2,169 bytes
コンパイル時間 3,894 ms
コンパイル使用メモリ 77,968 KB
実行使用メモリ 56,368 KB
最終ジャッジ日時 2024-05-07 09:47:41
合計ジャッジ時間 17,849 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
54,120 KB
testcase_01 AC 135 ms
54,284 KB
testcase_02 AC 145 ms
54,292 KB
testcase_03 AC 147 ms
54,280 KB
testcase_04 AC 135 ms
54,332 KB
testcase_05 AC 136 ms
54,232 KB
testcase_06 AC 135 ms
54,140 KB
testcase_07 AC 136 ms
54,128 KB
testcase_08 AC 134 ms
54,492 KB
testcase_09 AC 137 ms
54,208 KB
testcase_10 AC 134 ms
53,996 KB
testcase_11 AC 134 ms
54,176 KB
testcase_12 AC 139 ms
54,384 KB
testcase_13 AC 138 ms
54,428 KB
testcase_14 AC 140 ms
54,468 KB
testcase_15 AC 134 ms
54,388 KB
testcase_16 AC 133 ms
54,024 KB
testcase_17 AC 136 ms
54,120 KB
testcase_18 AC 135 ms
54,124 KB
testcase_19 AC 135 ms
54,272 KB
testcase_20 AC 136 ms
54,264 KB
testcase_21 AC 137 ms
54,280 KB
testcase_22 AC 135 ms
54,272 KB
testcase_23 AC 147 ms
54,200 KB
testcase_24 AC 133 ms
54,056 KB
testcase_25 AC 143 ms
54,476 KB
testcase_26 AC 141 ms
54,108 KB
testcase_27 AC 139 ms
54,196 KB
testcase_28 AC 137 ms
54,056 KB
testcase_29 AC 139 ms
54,264 KB
testcase_30 AC 136 ms
53,960 KB
testcase_31 AC 138 ms
53,996 KB
testcase_32 AC 137 ms
54,140 KB
testcase_33 AC 140 ms
54,128 KB
testcase_34 AC 133 ms
53,868 KB
testcase_35 AC 135 ms
54,088 KB
testcase_36 AC 137 ms
53,908 KB
testcase_37 AC 134 ms
54,284 KB
testcase_38 AC 137 ms
54,212 KB
testcase_39 AC 135 ms
54,180 KB
testcase_40 AC 139 ms
54,108 KB
testcase_41 AC 140 ms
54,452 KB
testcase_42 AC 136 ms
54,364 KB
testcase_43 AC 137 ms
54,376 KB
testcase_44 AC 138 ms
54,148 KB
testcase_45 AC 136 ms
54,076 KB
testcase_46 AC 140 ms
54,120 KB
testcase_47 AC 142 ms
54,244 KB
testcase_48 AC 143 ms
54,392 KB
testcase_49 AC 136 ms
54,268 KB
testcase_50 AC 135 ms
54,232 KB
testcase_51 AC 134 ms
54,260 KB
testcase_52 AC 144 ms
54,384 KB
testcase_53 AC 137 ms
54,400 KB
testcase_54 AC 134 ms
54,372 KB
testcase_55 AC 137 ms
54,272 KB
testcase_56 AC 141 ms
54,136 KB
testcase_57 AC 142 ms
54,288 KB
testcase_58 AC 138 ms
54,112 KB
testcase_59 AC 142 ms
54,160 KB
testcase_60 AC 139 ms
54,156 KB
testcase_61 AC 137 ms
54,116 KB
testcase_62 AC 134 ms
54,128 KB
testcase_63 AC 140 ms
53,984 KB
testcase_64 AC 135 ms
54,100 KB
testcase_65 AC 135 ms
54,368 KB
testcase_66 AC 141 ms
54,252 KB
testcase_67 AC 144 ms
54,228 KB
testcase_68 AC 142 ms
54,408 KB
testcase_69 AC 142 ms
54,548 KB
testcase_70 AC 138 ms
54,272 KB
testcase_71 AC 143 ms
54,324 KB
testcase_72 AC 137 ms
54,180 KB
testcase_73 AC 142 ms
53,996 KB
testcase_74 AC 135 ms
53,944 KB
testcase_75 AC 142 ms
54,116 KB
testcase_76 AC 136 ms
54,252 KB
testcase_77 AC 140 ms
56,368 KB
testcase_78 AC 144 ms
54,392 KB
testcase_79 AC 133 ms
54,236 KB
testcase_80 AC 133 ms
54,208 KB
testcase_81 AC 132 ms
53,848 KB
testcase_82 AC 135 ms
54,132 KB
testcase_83 AC 136 ms
54,156 KB
testcase_84 AC 138 ms
53,888 KB
testcase_85 AC 135 ms
53,840 KB
testcase_86 AC 132 ms
54,148 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[][] dp = new long[100][100];
		dp[0][0] = 1;
		for (int i = 1; i < 100; ++i) {
			for (int j = 0; j <= i; ++j) {
				if (j > 0)
					dp[i][j] = dp[i - 1][j - 1] * j % MODULO;
				if (j <= i - 1)
					dp[i][j] += dp[i - 1][j] * (j + 1) % MODULO;
				dp[i][j] %= MODULO;
			}
		}
		long[][] dp3 = new long[100][100];
		dp3[1][0] = 1;
		for (int i = 2; i < 100; ++i) {
			for (int j = 0; j <= i; ++j) {
				if (j > 0)
					dp3[i][j] = dp3[i - 1][j - 1] * j % MODULO;
				if (j <= i - 1) {
					dp3[i][j] += (dp3[i - 1][j] * j + dp[i - 1][j]) % MODULO;
				}
				dp3[i][j] %= MODULO;
			}
		}
		dp3[0][0] = 1;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if (k == 0) {
			System.out.println(dp[n][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();
		}
                Arrays.sort(a);
		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) {
					if (f && l == diff[i]) {
						dp1[j] += dp1[j - l] * dp[(int) diff[i]][l] % MODULO;
					} else
						dp1[j] += dp1[j - l] * dp3[(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 & (1L << i)) > 0 && (max & (1L << 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));
	}
}
0