結果

問題 No.2541 Divide 01 String
ユーザー titiatitia
提出日時 2023-11-24 21:42:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 483 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2023-11-24 21:42:42
合計ジャッジ時間 4,529 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,856 KB
testcase_01 AC 30 ms
9,856 KB
testcase_02 AC 29 ms
9,856 KB
testcase_03 AC 66 ms
9,984 KB
testcase_04 AC 146 ms
10,112 KB
testcase_05 AC 265 ms
10,368 KB
testcase_06 AC 124 ms
10,112 KB
testcase_07 AC 239 ms
10,368 KB
testcase_08 AC 254 ms
10,496 KB
testcase_09 AC 256 ms
10,496 KB
testcase_10 AC 258 ms
10,496 KB
testcase_11 AC 235 ms
10,496 KB
testcase_12 AC 237 ms
10,496 KB
testcase_13 AC 30 ms
9,856 KB
testcase_14 AC 29 ms
9,856 KB
testcase_15 AC 29 ms
9,856 KB
testcase_16 AC 30 ms
9,856 KB
testcase_17 AC 29 ms
9,856 KB
testcase_18 AC 151 ms
10,240 KB
testcase_19 AC 175 ms
10,240 KB
testcase_20 AC 146 ms
10,240 KB
testcase_21 AC 117 ms
10,240 KB
testcase_22 AC 116 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
S=input().strip()

mod=998244353

# 直前で途切れる、前から繋がっていて1が入っていない、前から繋がっていて1が入っている
DP=[1,0,0]

for s in S:
    NDP=[0,0,0]
    if s=="0":
        NDP[0]+=DP[2]
        NDP[1]+=DP[0]+DP[1]
        NDP[2]+=DP[2]
    else:
        NDP[0]+=DP[0]+DP[1]+DP[2]
        NDP[1]+=0
        NDP[2]+=DP[0]+DP[1]+DP[2]

    DP=[x%mod for x in NDP]

print(DP[0]%mod)
0