結果

問題 No.2541 Divide 01 String
コンテスト
ユーザー flygon
提出日時 2023-11-24 21:23:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 511 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 248 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 64,896 KB
最終ジャッジ日時 2026-04-13 12:08:54
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n = int(input())
s = input().rstrip()
dp = [0]*(n+1)
dp[0] = 1
last = -1
for i in range(1,n+1):
    if s[i-1] == "1":
        dp[i] += dp[i-1]
        last = i
    elif last != -1:
        dp[i] += dp[last-1]
    dp[i] += dp[i-1]
    dp[i] %= 998244353
print((dp[-1]-dp[-2])%998244353)

0