結果

問題 No.1426 Got a Covered OR
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-17 21:16:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 114,280 KB
最終ジャッジ日時 2024-04-27 13:46:21
合計ジャッジ時間 3,228 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,092 KB
testcase_01 AC 35 ms
53,260 KB
testcase_02 AC 34 ms
53,084 KB
testcase_03 AC 33 ms
53,160 KB
testcase_04 AC 33 ms
53,484 KB
testcase_05 AC 33 ms
54,124 KB
testcase_06 AC 34 ms
53,544 KB
testcase_07 AC 35 ms
53,076 KB
testcase_08 AC 33 ms
52,992 KB
testcase_09 AC 33 ms
53,156 KB
testcase_10 AC 34 ms
52,728 KB
testcase_11 AC 33 ms
53,000 KB
testcase_12 AC 94 ms
94,200 KB
testcase_13 AC 103 ms
98,256 KB
testcase_14 AC 90 ms
91,724 KB
testcase_15 AC 88 ms
91,952 KB
testcase_16 AC 60 ms
71,376 KB
testcase_17 AC 83 ms
77,256 KB
testcase_18 AC 176 ms
101,820 KB
testcase_19 AC 187 ms
101,412 KB
testcase_20 AC 114 ms
82,936 KB
testcase_21 AC 134 ms
89,700 KB
testcase_22 AC 124 ms
114,280 KB
testcase_23 AC 238 ms
110,064 KB
testcase_24 AC 56 ms
80,928 KB
testcase_25 AC 207 ms
109,292 KB
testcase_26 AC 59 ms
83,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0