結果

問題 No.2279 OR Insertion
ユーザー ああいいああいい
提出日時 2023-04-29 11:21:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,294 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 132,072 KB
最終ジャッジ日時 2024-04-29 07:41:55
合計ジャッジ時間 3,803 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
58,240 KB
testcase_01 AC 94 ms
76,216 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #


#頂点は1-index,下段は0-index
class LazySegTree:

    #単位元と結合と作用をここで定義
    Xunit = (0,0)
    Aunit = 0

    
    def Xf(self,x,y):
        return ((x[0] + y[0]) % P,x[1] + y[1])
    
    #Xf = max
    def Af(self,a,b):
        return a + b
    #AのXへの作用
    def operate(self,x,a):
        return ((x[0] + x[1] * a % P) % P,x[1])

    def __init__(self,N):
        self.N = N
        self.X = [self.Xunit] * (N + N)
        self.A = [self.Aunit] * (N + N)
    def build(self,seq):
        for i,x in enumerate(seq,self.N):
            self.X[i] = x
        for i in range(self.N-1,0,-1):
            self.X[i] = self.Xf(self.X[i<<1],self.X[i<<1 | 1])
    def eval_at(self,i):
        return self.operate(self.X[i],self.A[i])
    def propagate_at(self,i):
        self.X[i] = self.eval_at(i)
        self.A[i<<1] = self.Af(self.A[i<<1],self.A[i])
        self.A[i<<1 | 1] = self.Af(self.A[i<<1 | 1],self.A[i])
        self.A[i] = self.Aunit
    def propagate_above(self,i):
        H = i.bit_length() - 1
        for h in range(H,0,-1):
            self.propagate_at(i >> h)
    def recalc_above(self,i):
        while i > 1:
            i >>= 1
            self.X[i] = self.Xf(self.eval_at(i << 1),self.eval_at(i << 1 | 1))
    def update(self,i,x):
        i += self.N
        self.propagate_above(i)
        self.X[i] = x
        self.A[i] = self.Aunit
        self.recalc_above(i)
    def fold(self,L = 0,R = -1):
        if R == -1:R = self.N
        L += self.N
        R += self.N
        self.propagate_above(L // (L & -L))
        self.propagate_above(R // (R & -R) -1)
        vL = self.Xunit
        vR = self.Xunit
        while L < R:
            if L & 1:
                vL = self.Xf(vL,self.eval_at(L))
                L += 1
            if R & 1:
                R -= 1
                vR = self.Xf(self.eval_at(R),vR)
            L >>= 1
            R >>= 1
        return self.Xf(vL,vR)
    def operate_range(self,L,R,x):
        #区間全体に作用させる
        L += self.N
        R += self.N
        L0 = L // (L & -L)
        R0 = R // (R & -R) - 1
        self.propagate_above(L0)
        self.propagate_above(R0)
        while L < R:
            if L & 1:
                self.A[L] = self.Af(self.A[L],x)
                L += 1
            if R & 1:
                R -= 1
                self.A[R] = self.Af(self.A[R],x)
            L >>= 1
            R >>= 1
        self.recalc_above(L0)
        self.recalc_above(R0)
    def write(self):
        print(self.X)
    def change(self,Xf,Xunit,Af,Aunit,operate):
        self.Xf = Xf
        self.Xunit = Xunit
        self.Af = Af
        self.Aunit = Aunit
        self.operate = operate

N = int(input())
S = input()

P = 998244353

ans = 0
for i in range(1,N + 1):
    seg = LazySegTree(N + 2)
    seg.build([(1,1)] + [(0,1)] * (N + 1))

    for j in range(N):
        now = seg.fold(j,j + 1)[0]
        #print(now)
        end = 0
        if i + j > N:
            end = N + 2
        else:
            if S[-(i+j)] == "0":
                end = N + 2
            else:
                end = i + j
        seg.operate_range(j + 1,end,now)
    last = seg.fold(N + 1,N + 2)[0]
    #print(last)
    ans += pow(2,(i-1),P) * (pow(2,N - 1,P) - last) % P
print(ans % P)
0