結果

問題 No.2219 Re:010
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-02-17 22:20:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 504 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 130,328 KB
最終ジャッジ日時 2023-09-26 19:37:04
合計ジャッジ時間 7,214 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,176 KB
testcase_01 AC 72 ms
71,196 KB
testcase_02 AC 70 ms
71,372 KB
testcase_03 AC 337 ms
119,820 KB
testcase_04 AC 122 ms
81,772 KB
testcase_05 AC 281 ms
104,780 KB
testcase_06 AC 143 ms
83,540 KB
testcase_07 AC 221 ms
96,592 KB
testcase_08 AC 333 ms
116,364 KB
testcase_09 AC 325 ms
114,848 KB
testcase_10 AC 264 ms
104,168 KB
testcase_11 AC 267 ms
102,344 KB
testcase_12 AC 239 ms
102,552 KB
testcase_13 AC 388 ms
122,516 KB
testcase_14 AC 390 ms
122,364 KB
testcase_15 AC 387 ms
122,692 KB
testcase_16 AC 384 ms
122,672 KB
testcase_17 AC 379 ms
122,496 KB
testcase_18 AC 139 ms
110,696 KB
testcase_19 AC 146 ms
110,836 KB
testcase_20 AC 504 ms
130,328 KB
testcase_21 AC 73 ms
70,948 KB
testcase_22 AC 73 ms
71,180 KB
testcase_23 AC 73 ms
71,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
mod = 998244353

L = [[0,0]]
for s in S:
    l = L[-1][:]
    if s == "0":
        l[0] += 1
    elif s == "?":
        l[1] += 1
    L.append(l)

R = [[0,0]]
for s in S[::-1]:
    l = R[-1][:]
    if s == "0":
        l[0] += 1
    elif s == "?":
        l[1] += 1
    R.append(l)

R = R[::-1]
ans = 0
for i,s in enumerate(S):
    if s == "0":
        continue
    l0,l1 = L[i]
    r0,r1 = R[i+1]
    # print(i,s,l1,l1,r0,r1)
    ans += l0*r0%mod*pow(2,l1+r1,mod)
    ans %= mod
    if r1:
        ans += l0*r1%mod*pow(2,l1+r1-1,mod)
        ans %= mod
    if l1:
        ans += r0*l1%mod*pow(2,l1+r1-1,mod)
        ans %= mod
    
    if r1*l1:
        ans += r1*l1%mod*pow(2,l1+r1-2,mod)
        ans %= mod

print(ans)
0