結果

問題 No.2019 Digits Filling for All Substrings
ユーザー 👑 rin204rin204
提出日時 2022-07-26 19:53:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 454 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 77,976 KB
最終ジャッジ日時 2023-09-23 10:53:07
合計ジャッジ時間 6,184 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,636 KB
testcase_01 AC 70 ms
71,276 KB
testcase_02 AC 68 ms
71,128 KB
testcase_03 AC 69 ms
71,340 KB
testcase_04 AC 127 ms
77,620 KB
testcase_05 AC 115 ms
77,716 KB
testcase_06 AC 111 ms
77,548 KB
testcase_07 AC 104 ms
77,336 KB
testcase_08 AC 145 ms
77,676 KB
testcase_09 AC 160 ms
77,920 KB
testcase_10 AC 160 ms
77,636 KB
testcase_11 AC 168 ms
77,620 KB
testcase_12 AC 163 ms
77,976 KB
testcase_13 AC 163 ms
77,880 KB
testcase_14 AC 89 ms
76,952 KB
testcase_15 AC 87 ms
76,916 KB
testcase_16 AC 93 ms
77,360 KB
testcase_17 AC 87 ms
77,000 KB
testcase_18 AC 90 ms
76,984 KB
testcase_19 AC 69 ms
71,560 KB
testcase_20 AC 70 ms
71,556 KB
testcase_21 AC 69 ms
71,356 KB
testcase_22 AC 70 ms
71,380 KB
testcase_23 AC 70 ms
71,556 KB
testcase_24 AC 138 ms
77,476 KB
testcase_25 AC 160 ms
77,268 KB
testcase_26 AC 123 ms
77,120 KB
testcase_27 AC 81 ms
76,848 KB
testcase_28 AC 82 ms
76,800 KB
testcase_29 AC 155 ms
77,272 KB
testcase_30 AC 182 ms
77,488 KB
testcase_31 AC 180 ms
77,520 KB
testcase_32 AC 116 ms
77,412 KB
testcase_33 AC 177 ms
77,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

n = int(input())
S = input()

dp = [0, 0, 0]
ans = 0
for s in S:
    if s == "?":
        lst = list(range(10))
    else:
        lst = [int(s)]
    for x in lst:
        ans += dp[-x % 3]
        if x % 3 == 0:
            ans += 1
        ans %= MOD
    ndp = [0] * 3
    for x in lst:
        ndp[x % 3] += 1
        for i in range(3):
            ndp[(i + x) % 3] += dp[i]
            ndp[(i + x) % 3] %= MOD
    dp = ndp
print(ans)
0