結果

問題 No.2541 Divide 01 String
ユーザー ShirotsumeShirotsume
提出日時 2023-08-29 17:08:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 363 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 94,000 KB
最終ジャッジ日時 2023-08-29 17:08:26
合計ジャッジ時間 4,988 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,504 KB
testcase_01 AC 69 ms
71,496 KB
testcase_02 AC 69 ms
71,256 KB
testcase_03 AC 83 ms
76,500 KB
testcase_04 AC 84 ms
77,096 KB
testcase_05 AC 118 ms
93,464 KB
testcase_06 AC 81 ms
76,920 KB
testcase_07 AC 109 ms
93,456 KB
testcase_08 AC 116 ms
93,688 KB
testcase_09 AC 113 ms
93,804 KB
testcase_10 AC 111 ms
94,000 KB
testcase_11 AC 110 ms
93,696 KB
testcase_12 AC 110 ms
93,784 KB
testcase_13 AC 70 ms
71,304 KB
testcase_14 AC 70 ms
71,264 KB
testcase_15 AC 69 ms
71,156 KB
testcase_16 AC 70 ms
71,308 KB
testcase_17 AC 70 ms
71,304 KB
testcase_18 AC 78 ms
77,356 KB
testcase_19 AC 80 ms
77,108 KB
testcase_20 AC 78 ms
77,120 KB
testcase_21 AC 78 ms
76,920 KB
testcase_22 AC 79 ms
76,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
mod = 998244353
dp = [[0] * 2 for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    if s[i] == '0':
        dp[i + 1][0] += dp[i][1] + dp[i][0]
        dp[i + 1][1] += dp[i][1]
    else:
        dp[i + 1][1] += dp[i][0] + dp[i][1]
        dp[i + 1][1] += dp[i][1]
    dp[i + 1][0] %= mod
    dp[i + 1][1] %= mod

print(dp[n][1])
0