結果

問題 No.1426 Got a Covered OR
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-03-12 22:57:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,961 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 108,288 KB
最終ジャッジ日時 2024-04-22 14:25:21
合計ジャッジ時間 4,112 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
74,752 KB
testcase_01 AC 64 ms
75,008 KB
testcase_02 AC 63 ms
74,752 KB
testcase_03 AC 63 ms
74,624 KB
testcase_04 AC 63 ms
74,624 KB
testcase_05 AC 63 ms
74,496 KB
testcase_06 AC 63 ms
74,368 KB
testcase_07 AC 63 ms
74,368 KB
testcase_08 AC 67 ms
74,624 KB
testcase_09 AC 67 ms
74,752 KB
testcase_10 AC 66 ms
74,880 KB
testcase_11 AC 64 ms
74,624 KB
testcase_12 AC 154 ms
97,024 KB
testcase_13 AC 172 ms
98,944 KB
testcase_14 AC 151 ms
96,000 KB
testcase_15 AC 148 ms
96,512 KB
testcase_16 AC 91 ms
85,248 KB
testcase_17 AC 130 ms
91,904 KB
testcase_18 AC 151 ms
100,352 KB
testcase_19 AC 149 ms
99,968 KB
testcase_20 AC 126 ms
93,056 KB
testcase_21 AC 138 ms
96,128 KB
testcase_22 AC 203 ms
108,288 KB
testcase_23 AC 161 ms
105,472 KB
testcase_24 AC 107 ms
95,744 KB
testcase_25 AC 201 ms
104,576 KB
testcase_26 AC 91 ms
98,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

累積ORがB
Bが最後に出たやつに包含されていない場合は0

X -> Y の区間について考える
長さをLとする

Xで既にあるbitは、自由にしてok
2^L
新たなbitは、1回登場すればおk
(2^L-1)

Aが正なのが嫌だ
0がある場合を省かなくてはいけない

X箇所0がある場合…
みたいに包除すればよい

"""

import sys
from sys import stdin

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    if r == 0:
        return 1
    return fac[n] * inv[n-r] * inv[r] % mod

mod = 10**9+7
fac,inv = modfac(200000,mod)

def popcnt(X):
    ret = 0
    while X > 0:
        if X % 2 == 1:
            ret += 1
        X //= 2
    return ret

N = int(stdin.readline())
B = list(map(int,stdin.readline().split()))

ans = 1

last = 0
for i in B:
    if i != -1:
        if last | i != i:
            print ("0")
            sys.exit()
        last = i

lastind = -1
last = 0
for i in range(N):

    if B[i] != -1:
        ready = popcnt(last)
        new = popcnt(B[i] ^ last)
        L = i-lastind

        tans = 0
        for znum in range(L+1):
            if znum == L and new > 0:
                continue
            now = pow(pow(2,L-znum,mod),ready,mod) * pow(pow(2,L-znum,mod)-1,new,mod)
            now *= modnCr(L,znum,mod,fac,inv)

            if znum % 2 == 0:
                tans += now
            else:
                tans -= now

        ans *= tans
        ans %= mod

        lastind = i
        last = B[i]

    #print (i,ans)

print (ans)
0