結果

問題 No.2019 Digits Filling for All Substrings
ユーザー ShirotsumeShirotsume
提出日時 2022-02-07 11:42:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 97,636 KB
最終ジャッジ日時 2023-09-02 20:37:59
合計ジャッジ時間 7,873 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,324 KB
testcase_01 AC 77 ms
71,292 KB
testcase_02 AC 76 ms
71,380 KB
testcase_03 AC 78 ms
71,336 KB
testcase_04 AC 193 ms
90,980 KB
testcase_05 AC 167 ms
87,064 KB
testcase_06 AC 164 ms
85,464 KB
testcase_07 AC 142 ms
83,176 KB
testcase_08 AC 248 ms
97,264 KB
testcase_09 AC 281 ms
97,560 KB
testcase_10 AC 284 ms
97,636 KB
testcase_11 AC 277 ms
97,636 KB
testcase_12 AC 279 ms
97,452 KB
testcase_13 AC 280 ms
97,532 KB
testcase_14 AC 100 ms
77,220 KB
testcase_15 AC 101 ms
77,484 KB
testcase_16 AC 109 ms
78,088 KB
testcase_17 AC 102 ms
77,144 KB
testcase_18 AC 101 ms
77,180 KB
testcase_19 AC 75 ms
71,320 KB
testcase_20 AC 76 ms
71,300 KB
testcase_21 AC 76 ms
71,176 KB
testcase_22 AC 77 ms
70,992 KB
testcase_23 AC 76 ms
71,296 KB
testcase_24 AC 212 ms
86,372 KB
testcase_25 AC 264 ms
90,144 KB
testcase_26 AC 173 ms
83,036 KB
testcase_27 AC 93 ms
76,308 KB
testcase_28 AC 91 ms
76,680 KB
testcase_29 AC 249 ms
89,108 KB
testcase_30 AC 314 ms
93,864 KB
testcase_31 AC 309 ms
93,508 KB
testcase_32 AC 160 ms
81,888 KB
testcase_33 AC 258 ms
89,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import mod


n = int(input())

s = input()

mod = 998244353
dp = [[0] * 3 for _ in range(n + 1)]


for i in range(n):
    if s[i] == '?':
        for j in range(3):
            for k in range(10):
                dp[i + 1][(j + k) % 3] += dp[i][j]
                dp[i + 1][(j + k) % 3] %= mod
        for k in range(10):
            dp[i + 1][k % 3] += 1
            dp[i + 1][k % 3] %= mod
    else:
        for j in range(3):
            dp[i + 1][(j + int(s[i])) % 3] += dp[i][j]
            dp[i + 1][(j + int(s[i])) % 3] %= mod
        dp[i + 1][int(s[i]) % 3] += 1
ans = 0

for i in range(1, n + 1):
    ans += dp[i][0]
    ans %= mod
print(ans)

    
0