結果

問題 No.462 6日知らずのコンピュータ
ユーザー はむ吉🐹
提出日時 2017-01-03 17:07:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 730 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 60,800 KB
最終ジャッジ日時 2024-12-16 06:28:59
合計ジャッジ時間 7,514 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 WA * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3
# Ref: #138103

import math


P = 10 ** 9 + 7


def bits(n):
    return {i for i, b in enumerate(reversed("{:b}".format(n))) if b == '1'}


def solve(n, xs, mod=P):
    if not xs:
        return math.factorial(n) % mod
    ys = sorted(xs)
    ans = 1
    for y_i, y_j in zip([0] + ys, ys + [2 ** n - 1]):
        bs_i = bits(y_i)
        bs_j = bits(y_j)
        if bs_i <= bs_j:
            ans = ans * math.factorial(len(bs_j) - len(bs_i)) & mod
        else:
            return 0
    return ans


def main():
    n, k = (int(x) for x in input().split())
    if k == 0:
        xs = []
    else:
        xs = [int(x) for x in input().split()]
    print(solve(n, xs))


if __name__ == '__main__':
    main()
0