結果

問題 No.1426 Got a Covered OR
ユーザー KudeKude
提出日時 2021-03-12 22:55:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,646 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 107,904 KB
最終ジャッジ日時 2024-04-22 14:23:23
合計ジャッジ時間 7,458 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
74,496 KB
testcase_01 AC 65 ms
74,368 KB
testcase_02 AC 65 ms
74,496 KB
testcase_03 AC 69 ms
74,496 KB
testcase_04 AC 67 ms
74,496 KB
testcase_05 AC 66 ms
74,384 KB
testcase_06 AC 65 ms
74,368 KB
testcase_07 AC 66 ms
74,624 KB
testcase_08 AC 64 ms
74,240 KB
testcase_09 AC 67 ms
74,624 KB
testcase_10 AC 66 ms
74,112 KB
testcase_11 AC 67 ms
74,496 KB
testcase_12 AC 280 ms
98,304 KB
testcase_13 AC 385 ms
100,620 KB
testcase_14 AC 303 ms
98,040 KB
testcase_15 AC 249 ms
97,880 KB
testcase_16 AC 149 ms
93,048 KB
testcase_17 AC 114 ms
92,600 KB
testcase_18 AC 173 ms
101,844 KB
testcase_19 AC 162 ms
101,504 KB
testcase_20 AC 136 ms
94,820 KB
testcase_21 AC 145 ms
97,828 KB
testcase_22 AC 1,646 ms
106,880 KB
testcase_23 AC 228 ms
107,904 KB
testcase_24 AC 87 ms
97,280 KB
testcase_25 AC 216 ms
107,008 KB
testcase_26 AC 89 ms
98,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9 + 7

fact_range = 10 ** 6
fact = [1] * (fact_range + 1)
for i in range(0, fact_range):
    fact[i+1] = fact[i] * (i + 1) % MOD

ifact = [1] * (fact_range + 1)
ifact[fact_range] = pow(fact[fact_range], MOD - 2, MOD)
for i in range(fact_range, 0, -1):
    ifact[i-1] = ifact[i] * i % MOD

def comb(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * ifact[n-k] % MOD * ifact[k] % MOD

n = int(input())
b = [0] + list(map(int, input().split()))
now = b[n]
r = n
ans = 1
for i in range(n)[::-1]:
    if b[i] == -1:
        continue
    if now & b[i] != b[i]:
        print(0)
        exit()
    L = r - i
    diff = bin(now ^ b[i]).count('1')
    fr = bin(b[i]).count('1')
    #print(i, diff, ln)
    tot = 0
    for ln in range(L + 1):
        t = 0
        for k in range(diff + 1):
            if k % 2 == 0:
                t += comb(diff, k) * pow(2, (diff - k) * ln, MOD) * pow(2, fr * ln, MOD)
            else:
                t -= comb(diff, k) * pow(2, (diff - k) * ln, MOD) * pow(2, fr * ln, MOD)
            #print(k, t)
        #print(t)
        if (L - ln) % 2 == 0:
            tot += comb(L, ln) * t
        else:
            tot -= comb(L, ln) * t
        tot %= MOD
    ans = ans * tot % MOD
    now = b[i]
    r = i
print(ans)
0