結果
問題 | No.462 6日知らずのコンピュータ |
ユーザー |
![]() |
提出日時 | 2020-02-14 14:58:58 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 1,349 bytes |
コンパイル時間 | 2,807 ms |
コンパイル使用メモリ | 77,616 KB |
実行使用メモリ | 41,804 KB |
最終ジャッジ日時 | 2024-10-06 07:56:41 |
合計ジャッジ時間 | 16,532 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 84 |
ソースコード
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; } } } }