結果

問題 No.2219 Re:010
ユーザー HydruHydru
提出日時 2023-02-17 23:08:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 1,273 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 132,648 KB
最終ジャッジ日時 2023-09-26 20:29:52
合計ジャッジ時間 4,813 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,348 KB
testcase_01 AC 69 ms
71,240 KB
testcase_02 AC 72 ms
71,188 KB
testcase_03 AC 180 ms
125,864 KB
testcase_04 AC 102 ms
79,100 KB
testcase_05 AC 152 ms
114,760 KB
testcase_06 AC 105 ms
83,036 KB
testcase_07 AC 124 ms
95,672 KB
testcase_08 AC 159 ms
120,100 KB
testcase_09 AC 161 ms
120,076 KB
testcase_10 AC 146 ms
107,372 KB
testcase_11 AC 134 ms
95,956 KB
testcase_12 AC 133 ms
95,528 KB
testcase_13 AC 182 ms
132,372 KB
testcase_14 AC 183 ms
132,384 KB
testcase_15 AC 182 ms
132,296 KB
testcase_16 AC 180 ms
132,456 KB
testcase_17 AC 180 ms
132,416 KB
testcase_18 AC 144 ms
132,212 KB
testcase_19 AC 146 ms
132,220 KB
testcase_20 AC 168 ms
132,648 KB
testcase_21 AC 69 ms
71,356 KB
testcase_22 AC 73 ms
71,228 KB
testcase_23 AC 69 ms
71,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353

class combination():
    def __init__(self,n,mod):
    
        self.mod=mod
        self.fact = [1,1] # x!
        self.factinv = [1,1] # (x!)^(-1)
        inv = [0,1]
        for i in range(2,n+1):
            self.fact.append((self.fact[-1]*i)%mod)
            inv.append((-inv[mod%i]*(mod//i))%mod)
            self.factinv.append((self.factinv[-1]*inv[-1])%mod)

    def cmb(self,n,r):
        r=min(r,n-r)
        return self.fact[n]*self.factinv[r]*self.factinv[n-r]%self.mod

S=input()
cntr=[0,0,0]
for s in S:
    if s=="0":
        cntr[0]+=1
    elif s=="1":
        cntr[1]+=1
    else:
        cntr[2]+=1
cntl=[0,0,0]

C=combination(len(S)+1,mod)
pow_2=[1]
for _ in range(len(S)+1):
    pow_2.append(pow_2[-1]*2%mod)

ans=0
for s in S:
    if s=="0":
        cntr[0]-=1
        cntl[0]+=1
        continue
    if s=="1":
        cntr[1]-=1
        x=cntl[2]
        y=cntr[2]
        ans+=(cntl[0]*pow_2[x]+x*pow_2[max(0,x-1)])*(cntr[0]*pow_2[y]+y*pow_2[max(0,y-1)])
        ans%=mod
        cntl[1]+=1
        continue
    if s=="?":
        cntr[2]-=1
        x=cntl[2]
        y=cntr[2]
        ans+=(cntl[0]*pow_2[x]+x*pow_2[max(0,x-1)])*(cntr[0]*pow_2[y]+y*pow_2[max(0,y-1)])
        ans%=mod
        cntl[2]+=1
        continue

print(ans)
0