結果

問題 No.462 6日知らずのコンピュータ
ユーザー 37zigen37zigen
提出日時 2016-12-13 18:58:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 4,342 ms
コンパイル使用メモリ 80,448 KB
実行使用メモリ 56,636 KB
最終ジャッジ日時 2023-08-20 02:08:58
合計ジャッジ時間 17,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,548 KB
testcase_01 AC 115 ms
55,872 KB
testcase_02 AC 120 ms
56,124 KB
testcase_03 AC 121 ms
56,180 KB
testcase_04 AC 112 ms
56,400 KB
testcase_05 AC 112 ms
55,928 KB
testcase_06 AC 111 ms
56,008 KB
testcase_07 AC 112 ms
56,144 KB
testcase_08 AC 112 ms
55,708 KB
testcase_09 AC 114 ms
56,148 KB
testcase_10 AC 109 ms
54,232 KB
testcase_11 AC 110 ms
55,908 KB
testcase_12 AC 112 ms
56,400 KB
testcase_13 AC 114 ms
56,140 KB
testcase_14 AC 119 ms
56,460 KB
testcase_15 AC 115 ms
56,408 KB
testcase_16 AC 115 ms
56,516 KB
testcase_17 AC 116 ms
56,056 KB
testcase_18 AC 111 ms
55,996 KB
testcase_19 AC 112 ms
56,256 KB
testcase_20 AC 116 ms
56,032 KB
testcase_21 AC 116 ms
55,944 KB
testcase_22 AC 113 ms
56,092 KB
testcase_23 AC 123 ms
55,844 KB
testcase_24 AC 113 ms
55,572 KB
testcase_25 AC 124 ms
55,908 KB
testcase_26 AC 118 ms
55,952 KB
testcase_27 AC 113 ms
56,248 KB
testcase_28 AC 112 ms
56,324 KB
testcase_29 AC 116 ms
56,116 KB
testcase_30 AC 111 ms
56,328 KB
testcase_31 AC 111 ms
56,228 KB
testcase_32 AC 115 ms
56,148 KB
testcase_33 AC 117 ms
55,920 KB
testcase_34 AC 117 ms
55,532 KB
testcase_35 AC 112 ms
56,256 KB
testcase_36 AC 112 ms
56,244 KB
testcase_37 AC 119 ms
55,808 KB
testcase_38 AC 115 ms
56,212 KB
testcase_39 AC 113 ms
56,296 KB
testcase_40 AC 118 ms
56,024 KB
testcase_41 AC 119 ms
56,068 KB
testcase_42 AC 116 ms
55,936 KB
testcase_43 AC 111 ms
55,716 KB
testcase_44 AC 114 ms
55,724 KB
testcase_45 AC 116 ms
55,848 KB
testcase_46 AC 114 ms
56,088 KB
testcase_47 AC 117 ms
55,908 KB
testcase_48 AC 117 ms
55,836 KB
testcase_49 AC 114 ms
55,640 KB
testcase_50 AC 116 ms
55,632 KB
testcase_51 AC 114 ms
55,640 KB
testcase_52 AC 124 ms
55,904 KB
testcase_53 AC 117 ms
56,340 KB
testcase_54 AC 114 ms
56,020 KB
testcase_55 AC 115 ms
56,452 KB
testcase_56 AC 122 ms
56,368 KB
testcase_57 AC 118 ms
56,600 KB
testcase_58 AC 117 ms
55,520 KB
testcase_59 AC 120 ms
55,764 KB
testcase_60 AC 119 ms
56,008 KB
testcase_61 AC 115 ms
55,556 KB
testcase_62 AC 112 ms
55,852 KB
testcase_63 AC 118 ms
55,932 KB
testcase_64 AC 112 ms
56,076 KB
testcase_65 AC 114 ms
56,024 KB
testcase_66 AC 118 ms
56,148 KB
testcase_67 AC 120 ms
55,556 KB
testcase_68 AC 121 ms
55,736 KB
testcase_69 AC 120 ms
56,088 KB
testcase_70 AC 118 ms
56,052 KB
testcase_71 AC 119 ms
55,764 KB
testcase_72 AC 116 ms
55,684 KB
testcase_73 AC 116 ms
56,636 KB
testcase_74 AC 113 ms
56,032 KB
testcase_75 AC 121 ms
55,836 KB
testcase_76 AC 112 ms
56,080 KB
testcase_77 AC 120 ms
55,592 KB
testcase_78 AC 118 ms
55,768 KB
testcase_79 AC 112 ms
56,036 KB
testcase_80 AC 109 ms
53,964 KB
testcase_81 AC 111 ms
54,292 KB
testcase_82 AC 114 ms
53,876 KB
testcase_83 AC 113 ms
55,708 KB
testcase_84 AC 111 ms
55,848 KB
testcase_85 AC 111 ms
55,920 KB
testcase_86 AC 114 ms
55,940 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[99] = pow(fac[99], MODULO - 2);
		for (int i = 98; i >= 0; --i) {
			invfac[i] = invfac[i + 1] * (i + 1) % 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();
		}
		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 ans = 1;
		for (int i = 0; i < k + 1; ++i) {
			ans = (ans * fac[(int) diff[i]]) % MODULO;
		}
		System.out.println(ans);

	}

	static long count(long min, long max) {
		for (int i = 0; i < 63; ++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));
	}

	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