結果

問題 No.1426 Got a Covered OR
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-17 20:58:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,420 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 81,884 KB
実行使用メモリ 114,284 KB
最終ジャッジ日時 2024-04-27 13:30:33
合計ジャッジ時間 2,943 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,352 KB
testcase_01 AC 36 ms
52,072 KB
testcase_02 AC 34 ms
52,884 KB
testcase_03 AC 35 ms
52,072 KB
testcase_04 WA -
testcase_05 AC 35 ms
53,880 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 35 ms
54,096 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 124 ms
114,284 KB
testcase_23 WA -
testcase_24 AC 54 ms
80,168 KB
testcase_25 WA -
testcase_26 AC 60 ms
84,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main0(n,b):
  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):
      # 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
    if x==now:
      l=i+1
    elif l==i:
      now|=x
      l=i+1
    else:
      cnt1=bin(now).count('1')
      t=x-now
      t=bin(t).count('1')
      now|=x
      r=i
      # 区間[l,r]でビットがt個立つ
      length=r+1-l
      ans*=func(length,cnt1,t)
      ans%=mod
      cnt1+=t
  return ans

if __name__=='__main__':
  n=int(input())
  b=list(map(int,input().split()))
  ret0=main0(n,b)
  print(ret0)
0