結果
| 問題 |
No.462 6日知らずのコンピュータ
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-02 10:40:01 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,866 bytes |
| コンパイル時間 | 2,225 ms |
| コンパイル使用メモリ | 77,496 KB |
| 実行使用メモリ | 37,096 KB |
| 最終ジャッジ日時 | 2024-10-11 08:54:02 |
| 合計ジャッジ時間 | 9,060 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 54 WA * 30 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
long current = 0;
int k = sc.nextInt();
long ans = 1;
for (int i = 0; i < k; i++) {
long x = sc.nextLong();
if ((current | x) == x) {
ans *= kaijo(pop(x) - pop(current));
ans %= MOD;
} else {
ans = 0;
}
current = x;
}
long last = (1L << n) - 1;
if ((current | last) == last) {
ans *= kaijo(pop(last) - pop(current));
ans %= MOD;
} else {
ans = 0;
}
System.out.println(ans);
}
static long kaijo(int x) {
if (x == 0) {
return 1;
} else {
return x * kaijo(x - 1) % MOD;
}
}
static int pop(long x) {
int count = 0;
while (x > 0) {
if (x % 2 == 1) {
count++;
}
x /= 2;
}
return count;
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten