結果

問題 No.2219 Re:010
ユーザー ikomaikoma
提出日時 2023-02-17 23:33:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 87,268 KB
最終ジャッジ日時 2023-09-26 20:55:51
合計ジャッジ時間 6,571 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,576 KB
testcase_01 AC 93 ms
71,512 KB
testcase_02 AC 96 ms
71,644 KB
testcase_03 AC 287 ms
85,904 KB
testcase_04 WA -
testcase_05 AC 249 ms
80,160 KB
testcase_06 AC 148 ms
78,824 KB
testcase_07 AC 198 ms
79,372 KB
testcase_08 AC 279 ms
85,032 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 209 ms
79,432 KB
testcase_13 AC 322 ms
87,176 KB
testcase_14 WA -
testcase_15 AC 325 ms
87,048 KB
testcase_16 WA -
testcase_17 AC 321 ms
87,248 KB
testcase_18 AC 113 ms
80,772 KB
testcase_19 AC 116 ms
80,932 KB
testcase_20 WA -
testcase_21 AC 92 ms
71,648 KB
testcase_22 AC 89 ms
71,560 KB
testcase_23 AC 91 ms
71,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import Counter
S=list(input().strip())
MOD=998244353
cnt = Counter(S)
cnt0R = cnt["0"]
cntqR=cnt["?"]
cnt0L=0
cntqL=0
ans=0
for s in S:
    if s=="1":
        cntq=cntqL+cntqR
        ans += cnt0L*cnt0R%MOD*pow(2,cntq,MOD)%MOD
        if cntq>0:
            ans += cnt0L*cntqR%MOD*pow(2,cntq-1,MOD)%MOD
            ans += cntqL*cnt0R%MOD*pow(2,cntq-1,MOD)%MOD
        if cntq>1:ans += cntqL*cntqR%MOD*pow(2,cntq-2,MOD)%MOD
        ans%=MOD
    elif s=="0":
        cnt0L+=1
        cnt0R-=1
    else:
        cntqR-=1
        cntq=cntqL+cntqR
        ans += cnt0L*cnt0R%MOD*pow(2,cntq,MOD)%MOD
        if cntq>0:
            ans += cnt0L*cntqR%MOD*pow(2,cntq-1,MOD)%MOD
            ans += cntqL*cnt0R%MOD*pow(2,cntq-1,MOD)%MOD
        if cntq>1:ans += cntqL*cntqR%MOD*pow(2,cntq-2,MOD)%MOD
        cntqL+=1
print(ans)
0