結果

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

ソースコード

diff #
raw source code

n=int(input())
s=input()
res=[]
cnt=1
ans=0
for i in range(1,n):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        res.append((s[i-1],cnt))
        cnt=1
res.append((s[-1],cnt))

MOD=998244353
cnt0=0
cnt1=0
ans=1
for i in range(len(res)):
    if res[i][0]=='0':
        cnt0+=res[i][1]
    else:
        cnt1+=res[i][1]
        if cnt0>0:
            ans*=cnt0+cnt1+1
            ans%=MOD
        cnt0=0
        cnt1=0
print(ans)
0