結果

問題 No.2171 OR Assignment
ユーザー titia
提出日時 2022-12-25 01:36:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,821 ms / 3,500 ms
コード長 845 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 105,596 KB
最終ジャッジ日時 2024-11-18 08:46:03
合計ジャッジ時間 26,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

prev=[0]*30

mod=998244353

IND=[0]
DP=[1]

for i in range(1,N):
    NDP=[]
    NIND=[]
    a=A[i]
    
    for j in range(30):
        if (1<<j) & a!= 0:
            prev[j]=i

    sp=sorted(set(prev)|{i},reverse=True)
    SA=[a]*len(sp)
    now=a
    for j in range(len(sp)):
        now|=A[sp[j]]
        SA[j]=now

    s=i

    for j in range(len(SA)):
        if j+1<len(SA) and SA[j]==SA[j+1]:
            continue
        else:      
            score=0
            for ix in range(len(IND)):
                if IND[ix]<=s:
                    score=(score+DP[ix])%mod

            NDP.append(score)
            NIND.append(sp[j])

            if j+1<len(sp):
                s=sp[j+1]

    DP=NDP
    IND=NIND
    #print(DP,IND)

print(sum(DP)%mod)
0