結果
問題 | No.462 6日知らずのコンピュータ |
ユーザー |
![]() |
提出日時 | 2016-12-15 02:44:39 |
言語 | D (dmd 2.109.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,206 bytes |
コンパイル時間 | 1,957 ms |
コンパイル使用メモリ | 154,752 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-12 05:34:03 |
合計ジャッジ時間 | 3,994 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 WA * 16 RE * 42 |
ソースコード
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(int a, int 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!int).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 = 1; foreach (i; 0 .. K - 1) { int a = A[i], b = A[i + 1]; int d = (b - a).popcnt; ans = (ans * fact(d)) % mod; } return ans; } writeln(solve()); }