結果
| 問題 |
No.462 6日知らずのコンピュータ
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-12-15 02:52:56 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,280 bytes |
| コンパイル時間 | 1,530 ms |
| コンパイル使用メモリ | 156,472 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 05:34:33 |
| 合計ジャッジ時間 | 3,391 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 84 |
ソースコード
import std.algorithm;
import std.array;
import std.ascii;
import core.bitop;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }
bool contains(long a, long b) {
return (a & b) == b;
}
void main() {
immutable long mod = cast(long)(1e9 + 7);
long fact(long x) {
if (x == 0) return 1;
return x * fact(x - 1) % mod;
}
int N, K; readf("%s %s\n", &N, &K);
auto A = readln.chomp.split(" ").map!(to!long).array;
long solve() {
if (K == 0) return fact(N);
foreach (i; 0 .. K) {
foreach (j; i + 1 .. K) {
if (! (A[i].contains(A[j]) || A[j].contains(A[i]))) {
return 0;
}
}
}
A.sort!((a, b) => (a.popcnt < b.popcnt));
//log(A);
long ans = fact(A[0].popcnt);
foreach (i; 0 .. K - 1) {
auto a = A[i], b = A[i + 1];
auto d = (b - a).popcnt;
ans = (ans * fact(d)) % mod;
}
ans = (ans * fact(N - A.back.popcnt)) % mod;
return ans;
}
writeln(solve());
}
izuru_matsuura