結果
| 問題 |
No.1426 Got a Covered OR
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-17 21:16:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 272 ms / 2,000 ms |
| コード長 | 1,343 bytes |
| コンパイル時間 | 398 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 114,560 KB |
| 最終ジャッジ日時 | 2024-11-15 16:02:32 |
| 合計ジャッジ時間 | 3,928 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
def main1(n,b):
if n==1:return 1
mod=10**9+7
now=0
for x in b:
if x<0:continue
if (x&now)!=now:return 0
now|=x
def cmb(n,r,mod):
if (r<0 or r>n):
return 0
r=min(r,n-r)
return (g1[n]*g2[r]*g2[n-r])%mod
g1=[1,1] # g1[i]=i! % mod :階乗
g2=[1,1] # g2[i]=(i!)^(-1) % mod :階乗の逆元
inverse=[0,1]
for i in range(2,n+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
pow2=[1,2,4]
for _ in range(n):pow2.append(pow2[-1]*2%mod)
def func(l,cnt1,t):
# 長さlの数列の中で新たにt個のビットが立つ。cnt1個のビットは自由に選べる。包除原理
ret=0
for i in range(l+1):
# l個の要素の内、0になるのがi個ある。
tmp=pow(pow2[l-i]-1,t,mod)*cmb(l,i,mod)%mod
tmp=tmp*pow(pow2[l-i],cnt1,mod)%mod
ret+=tmp*(-1)**(i%2)
ret%=mod
return ret
ans=1
l,r=0,0
now=0
for i,x in enumerate(b):
if x<0:continue
cnt1=bin(now).count('1')
t=x-now
t=bin(t).count('1')
r=i
# 区間[l,r]でビットがt個立つ
length=r+1-l
ans*=func(length,cnt1,t)
ans%=mod
now|=x
l=i+1
return ans
if __name__=='__main__':
n=int(input())
b=list(map(int,input().split()))
ret1=main1(n,b)
print(ret1)