結果

問題 No.2219 Re:010
ユーザー 👑 H20H20
提出日時 2023-02-17 23:43:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 115,424 KB
最終ジャッジ日時 2023-09-26 21:04:32
合計ジャッジ時間 5,769 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,332 KB
testcase_01 AC 74 ms
71,516 KB
testcase_02 AC 75 ms
71,332 KB
testcase_03 AC 239 ms
110,128 KB
testcase_04 AC 108 ms
79,272 KB
testcase_05 AC 204 ms
95,956 KB
testcase_06 AC 122 ms
82,732 KB
testcase_07 AC 160 ms
92,080 KB
testcase_08 AC 223 ms
103,824 KB
testcase_09 AC 219 ms
103,160 KB
testcase_10 AC 186 ms
92,752 KB
testcase_11 AC 175 ms
94,904 KB
testcase_12 AC 174 ms
94,824 KB
testcase_13 AC 260 ms
115,208 KB
testcase_14 AC 259 ms
115,396 KB
testcase_15 AC 261 ms
115,424 KB
testcase_16 AC 260 ms
115,288 KB
testcase_17 AC 261 ms
115,228 KB
testcase_18 AC 116 ms
109,980 KB
testcase_19 AC 118 ms
110,456 KB
testcase_20 AC 319 ms
109,696 KB
testcase_21 AC 72 ms
71,468 KB
testcase_22 AC 72 ms
71,316 KB
testcase_23 AC 72 ms
71,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
S = list(input())
Q = [0]*len(S)
Z = [0]*len(S)
mod = 998244353
for i,s in enumerate(S):
    if s=='0':
        Z[i]=1
    if s=='?':
        Q[i]=1
ZAC = list(itertools.accumulate(Z))
QAC = list(itertools.accumulate(Q))
ans = 0

def modinv(a):
    return pow(a, mod-2, mod)
div2 = modinv(2)

for i,s in enumerate(S):
    if i==0 or i==len(S)-1:
        continue
    if s=='1' or s=='?':
        leftZ = ZAC[i-1]
        leftQ = QAC[i-1]
        rightZ = ZAC[-1]-ZAC[i]
        rightQ = QAC[-1]-QAC[i]
        left = (pow(2,leftQ,mod)*(leftZ+leftQ*div2))%mod
        right = (pow(2,rightQ,mod)*(rightZ+rightQ*div2))%mod
        ans = (ans+left*right)%mod
print(ans)
0