結果
問題 | No.462 6日知らずのコンピュータ |
ユーザー |
![]() |
提出日時 | 2017-08-26 16:05:35 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,262 bytes |
コンパイル時間 | 92 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-10-15 17:43:15 |
合計ジャッジ時間 | 4,234 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 84 |
ソースコード
# coding: utf-8 import math def II(): return int(input()) def ILI(): return list(map(int, input().split())) def read(): N, k = ILI() if k >= 1: a = ILI() else: a = None return N, k, a def solve(N, k, a): l_ele = [] if a is None: return math.factorial(N) % (10 ** 9 + 7) else: for i_a in a: s_bit = set() for ind, b in enumerate(reversed(str(bin(i_a)))): if b == "b": break if b == "1": s_bit.add(ind) l_ele.append((len(s_bit), s_bit)) l_ele.sort(key=lambda x: x[0]) ans = math.factorial(l_ele[0][0]) for i in range(len(l_ele)): if i < len(l_ele) - 1: len_dif = l_ele[i + 1][0] - l_ele[i][0] set_dif = l_ele[i + 1][1] - l_ele[i][1] if len_dif == 0: return 0 if len(set_dif) != len_dif: return 0 ans *= math.factorial(len_dif) else: ans *= math.factorial(N - l_ele[i][0]) return ans % (10 ** 9 + 7) def main(): params = read() print(solve(*params)) if __name__ == "__main__": main()