結果

問題 No.2219 Re:010
ユーザー flygonflygon
提出日時 2023-02-17 22:10:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 133,728 KB
最終ジャッジ日時 2023-09-26 19:26:10
合計ジャッジ時間 5,649 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,000 KB
testcase_01 AC 73 ms
71,000 KB
testcase_02 AC 74 ms
70,984 KB
testcase_03 AC 234 ms
111,200 KB
testcase_04 AC 111 ms
78,760 KB
testcase_05 AC 201 ms
99,352 KB
testcase_06 AC 122 ms
82,732 KB
testcase_07 AC 158 ms
90,032 KB
testcase_08 AC 220 ms
105,228 KB
testcase_09 AC 221 ms
104,968 KB
testcase_10 AC 192 ms
96,792 KB
testcase_11 AC 173 ms
92,192 KB
testcase_12 AC 172 ms
92,228 KB
testcase_13 AC 259 ms
117,952 KB
testcase_14 AC 256 ms
117,888 KB
testcase_15 AC 257 ms
117,836 KB
testcase_16 AC 256 ms
118,012 KB
testcase_17 AC 256 ms
117,844 KB
testcase_18 AC 133 ms
133,460 KB
testcase_19 AC 132 ms
133,448 KB
testcase_20 AC 301 ms
133,728 KB
testcase_21 AC 75 ms
71,008 KB
testcase_22 AC 73 ms
70,900 KB
testcase_23 AC 73 ms
70,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
mod = 998244353
ans = 0
n = len(s)
pre = []
hate = []
last = 0
nowh = 0
for i in range(n):
  si = s[i]
  hate.append(last)
  if si == "0":
    last += pow(2, nowh, mod)
  elif si == "?":
    last *= 2 
    last += pow(2, nowh, mod)
    nowh += 1
  last %= mod
  pre.append(last)

suf = []
hates = []
nowh = 0
last = 0
for i in range(n)[::-1]:
  si = s[i]
  hates.append(last)
  if si == "0":
    last += pow(2, nowh, mod)
  elif si == "?":
    last *= 2 
    last += pow(2, nowh, mod)
    nowh += 1
  last %= mod
  suf.append(last)

suf = suf[::-1]
hates = hates[::-1]
ans = 0
for i in range(1,n-1):
  if s[i] == "1":
    ans += pre[i] * suf[i] % mod
    ans %= mod
  elif s[i] == "?":
    ans += hate[i] * hates[i] % mod
    ans %= mod 
  
print(ans)
0