結果

問題 No.462 6日知らずのコンピュータ
コンテスト
ユーザー htensai
提出日時 2020-02-14 14:58:58
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 64 ms / 2,000 ms
+ 526µs
コード長 1,349 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,534 ms
コンパイル使用メモリ 86,224 KB
実行使用メモリ 43,076 KB
最終ジャッジ日時 2026-09-11 00:42:31
合計ジャッジ時間 10,159 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		Pop[] pops = new Pop[k + 2];
		pops[0] = new Pop(0);
		for (int i = 1; i <= k; i++) {
		    pops[i] = new Pop(sc.nextLong());
		}
		pops[k + 1] = new Pop((1L << n) - 1);
		Arrays.sort(pops);
		long ans = 1;
		for (int i = 0; i <= k; i++) {
		    ans *= pops[i + 1].getPop(pops[i]);
		    ans %= MOD;
		}
		System.out.println(ans);
    }
    
    static class Pop implements Comparable<Pop> {
        long value;
        int count;
        
        public Pop(long value) {
            this.value = value;
            while (value > 0) {
                count += value % 2;
                value /= 2;
            }
        }
        
        public int compareTo(Pop another) {
            return count - another.count;
        }
        
        public long getPop(Pop another) {
            if ((value & another.value) != another.value) {
                return 0;
            }
            return kaijo(count - another.count);
        }
        
        static long kaijo(long x) {
            if (x <= 1) {
                return 1;
            } else {
                return x * kaijo(x - 1) % MOD;
            }
        }
    }
}
0