結果

問題 No.1426 Got a Covered OR
ユーザー nok0nok0
提出日時 2021-01-17 11:12:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 679 ms / 2,000 ms
コード長 1,464 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 32,048 KB
最終ジャッジ日時 2024-05-06 23:40:16
合計ジャッジ時間 8,395 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
22,784 KB
testcase_01 AC 181 ms
22,784 KB
testcase_02 AC 173 ms
22,912 KB
testcase_03 AC 172 ms
22,780 KB
testcase_04 AC 169 ms
22,780 KB
testcase_05 AC 168 ms
22,660 KB
testcase_06 AC 171 ms
22,784 KB
testcase_07 AC 171 ms
22,656 KB
testcase_08 AC 170 ms
22,912 KB
testcase_09 AC 172 ms
22,780 KB
testcase_10 AC 171 ms
22,908 KB
testcase_11 AC 181 ms
22,784 KB
testcase_12 AC 193 ms
26,344 KB
testcase_13 AC 202 ms
27,136 KB
testcase_14 AC 197 ms
26,240 KB
testcase_15 AC 194 ms
26,108 KB
testcase_16 AC 174 ms
23,168 KB
testcase_17 AC 203 ms
23,676 KB
testcase_18 AC 405 ms
28,428 KB
testcase_19 AC 410 ms
28,604 KB
testcase_20 AC 271 ms
25,084 KB
testcase_21 AC 311 ms
26,144 KB
testcase_22 AC 216 ms
29,356 KB
testcase_23 AC 679 ms
32,044 KB
testcase_24 AC 192 ms
32,048 KB
testcase_25 AC 503 ms
30,892 KB
testcase_26 AC 513 ms
31,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


mod = 1_000_000_007
MAX = 10 ** 5 + 10
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, MAX + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


def COM(n, r):
    if (r < 0) or (n < r):
        return 0
    return fact[n] * factinv[r] * factinv[n - r] % mod


n = int(readline())
b = list(map(int, readline().split()))
base, cont, res = 0, 0, 1
for v in b:
    if v == -1:
        cont += 1
    else:
        if (v | (base ^ v)) != v:
            print(0)
            exit()

        a = popcnt(base)
        b = popcnt(v)
        x = b - a
        tmp = 0
        for i in range(0, x + 1):
            tmp += COM(x, i) * pow((pow(2, b - i, mod) - 1), cont + 1, mod) * (-1 if i % 2 else 1)
            tmp %= mod
        res *= tmp
        res %= mod

        cont, base = 0, v

print(res)
0