結果
問題 | No.462 6日知らずのコンピュータ |
ユーザー |
|
提出日時 | 2018-06-23 00:09:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 138 ms / 2,000 ms |
コード長 | 917 bytes |
コンパイル時間 | 4,070 ms |
コンパイル使用メモリ | 77,696 KB |
実行使用メモリ | 54,444 KB |
最終ジャッジ日時 | 2024-06-30 18:10:57 |
合計ジャッジ時間 | 17,205 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 84 |
ソースコード
import java.util.*; public class No462{ static long mod = (long)Math.pow(10, 9) + 7; public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int k = sc.nextInt(); if(k == 0){ System.out.println(fact(N)); return; } long[] a = new long[k+1]; for(int i = 0; i < k; i++){ a[i] = sc.nextLong(); } a[k] = (long)Math.pow(2, N) - 1; Arrays.sort(a); // System.out.println(Arrays.toString(a)); for(int i = 1; i < k+1; i++){ if((a[i] & a[i-1]) != a[i-1]){ System.out.println(0); return; } } long ans = fact(Long.bitCount(a[0])); for(int i = 1; i < k+1; i++){ long xor = a[i]^a[i-1]; ans *= fact(Long.bitCount(xor)); ans %= mod; } System.out.println(ans); } private static long fact(long n){ if(n == 0) return 1; long ret = 1; for(long i = n; i > 0; i--){ ret = ret*i%mod; } return ret; } }