結果

問題 No.1426 Got a Covered OR
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-15 16:10:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 2,432 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 93,952 KB
最終ジャッジ日時 2024-04-24 18:52:16
合計ジャッジ時間 3,738 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,480 KB
testcase_01 AC 40 ms
52,608 KB
testcase_02 AC 39 ms
52,480 KB
testcase_03 AC 42 ms
52,096 KB
testcase_04 AC 40 ms
52,736 KB
testcase_05 AC 39 ms
52,224 KB
testcase_06 AC 39 ms
52,224 KB
testcase_07 AC 38 ms
52,608 KB
testcase_08 AC 39 ms
52,352 KB
testcase_09 AC 42 ms
52,096 KB
testcase_10 AC 39 ms
52,608 KB
testcase_11 AC 40 ms
52,480 KB
testcase_12 AC 117 ms
83,200 KB
testcase_13 AC 125 ms
85,632 KB
testcase_14 AC 110 ms
82,432 KB
testcase_15 AC 120 ms
82,560 KB
testcase_16 AC 77 ms
76,544 KB
testcase_17 AC 90 ms
76,928 KB
testcase_18 AC 134 ms
87,424 KB
testcase_19 AC 137 ms
86,784 KB
testcase_20 AC 101 ms
79,488 KB
testcase_21 AC 118 ms
82,176 KB
testcase_22 AC 114 ms
91,264 KB
testcase_23 AC 182 ms
93,952 KB
testcase_24 AC 73 ms
83,456 KB
testcase_25 AC 164 ms
93,056 KB
testcase_26 AC 174 ms
92,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9+7
D = 32


class Combination:
    """
    SIZEが10**6程度以下の二項係数を何回も呼び出したいときに使う
    使い方:
    comb = Combination(SIZE, MOD)
    comb(10, 3) => 120
    """

    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.__make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def nPk(self, n, k):
        if k < 0 or k > n:
            return 0
        return self.fact[n] * self.inv[n - k] % self.MOD

    def nHk(self, n, k):
        if k == 0:
            return 1
        return self.__call__(n + k - 1, k)

    def __make_factorial_list(self, N):
        self.fact = [1] * (N + 1)
        self.inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            self.fact[i] = (self.fact[i - 1] * i) % MOD
        self.inv[N] = pow(self.fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            self.inv[i - 1] = (self.inv[i] * i) % MOD
        return


def main():
    N = int(input())
    B = list(map(int, input().split()))
    comb = Combination(N+1000, mod)
    pow2 = [1] * (N + 1)
    for i in range(1, N + 1):
        pow2[i] = pow2[i-1] * 2 % mod

    def ok(A, B):
        for i in range(D):
            a = (A >> i) & 1
            b = (B >> i) & 1
            if a == 1 and b == 0:
                return 0
        return 1

    def enum(A, B, step):
        res = 0
        for zero in range(step + 1):
            cnt = 1
            for i in range(D):
                a = (A >> i) & 1
                b = (B >> i) & 1
                if a == b == 1:
                    cnt *= pow2[step - zero]
                    cnt %= mod
                if a == 0 and b == 1:
                    cnt *= pow2[step - zero] - 1
                    cnt %= mod
            if zero % 2 == 1:
                cnt = -cnt
                # cnt = mod - cnt
            res = (res + cnt * comb(step, zero)) % mod
        return res

    ans = 1
    i = 0
    a = 0
    step = 0
    while i < N:
        b = B[i]
        i += 1
        if b == -1:
            step += 1
            continue
        if not ok(a, b):
            return 0
        ans *= enum(a, b, step + 1)
        ans %= mod
        a = b
        step = 0
    return ans


print(main())
0