結果

問題 No.3500 01 String
コンテスト
ユーザー はじっこゆーれー
提出日時 2026-04-17 23:28:25
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 742 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 867 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 16,084 KB
最終ジャッジ日時 2026-04-17 23:29:12
合計ジャッジ時間 5,639 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def solve():
    N = int(input())
    A = input()
    
    MOD = 998244353
    ans = 1
    
    current_length = 0
    has_zero = False
    has_one = False
    
    for i in range(N):
        current_length += 1
        
        if A[i] == '0':
            has_zero = True
        if A[i] == '1':
            has_one = True
            
        if A[i] == '1' and i + 1 < N and A[i+1] == '0':
            if has_zero and has_one:
                ans = (ans * (current_length + 1)) % MOD
            
            current_length = 0
            has_zero = False
            has_one = False
            
    if has_zero and has_one:
        ans = (ans * (current_length + 1)) % MOD
        
    print(ans)

if __name__ == '__main__':
    solve()
0