結果

問題 No.3500 01 String
コンテスト
ユーザー nasu
提出日時 2026-04-18 18:11:12
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 542 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 167 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 72,960 KB
最終ジャッジ日時 2026-04-18 18:11:16
合計ジャッジ時間 3,004 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

modint = 998244353
n = int(input())
a = input()

to_z = [0]*n
to_o = [0]*n

flag_z = False
flag_o = False

for i in range(n):
	if a[i] == "1":
		to_z[i] = to_z[i-1] + 1
	else:
		to_z[i] = 0

for i in range(n):
	if a[-1-i] == "0":
		to_o[-1-i] = to_o[-i] + 1
	else:
		to_o[-1-i] = 0

ans = 1
flag = True
z, o = 0, 0
i = 0
while i < n and a[i] == "1":
	i+=1

while i < n:

	o = to_o[i]
	flag = False
	i += o

	if i == n:
		break

	while i < n and a[i] == "1":
		i += 1
	z = to_z[i-1]

	ans = (ans + ans * (z + o) ) % modint

print(ans % modint)
0