結果

問題 No.2019 Digits Filling for All Substrings
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-07-22 22:08:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,372 KB
実行使用メモリ 86,900 KB
最終ジャッジ日時 2023-09-17 10:16:24
合計ジャッジ時間 5,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,024 KB
testcase_01 AC 76 ms
71,424 KB
testcase_02 AC 73 ms
71,092 KB
testcase_03 AC 76 ms
71,028 KB
testcase_04 AC 123 ms
82,644 KB
testcase_05 AC 114 ms
81,240 KB
testcase_06 AC 110 ms
80,428 KB
testcase_07 AC 102 ms
79,820 KB
testcase_08 AC 137 ms
86,368 KB
testcase_09 AC 153 ms
86,656 KB
testcase_10 AC 153 ms
86,704 KB
testcase_11 AC 152 ms
86,900 KB
testcase_12 AC 154 ms
86,704 KB
testcase_13 AC 149 ms
86,872 KB
testcase_14 AC 92 ms
76,636 KB
testcase_15 AC 91 ms
76,528 KB
testcase_16 AC 91 ms
76,476 KB
testcase_17 AC 91 ms
76,536 KB
testcase_18 AC 89 ms
76,536 KB
testcase_19 AC 73 ms
71,156 KB
testcase_20 AC 72 ms
70,992 KB
testcase_21 AC 73 ms
71,132 KB
testcase_22 AC 73 ms
71,032 KB
testcase_23 AC 74 ms
70,956 KB
testcase_24 AC 125 ms
80,788 KB
testcase_25 AC 140 ms
82,588 KB
testcase_26 AC 113 ms
79,504 KB
testcase_27 AC 85 ms
76,604 KB
testcase_28 AC 85 ms
76,768 KB
testcase_29 AC 140 ms
82,032 KB
testcase_30 AC 158 ms
84,944 KB
testcase_31 AC 159 ms
84,604 KB
testcase_32 AC 111 ms
79,156 KB
testcase_33 AC 138 ms
82,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

2019:
?がいくつ含まれるか
他の桁の総和mod3はいくつか
これが列挙できればok

?の個数が 1~|S|
他の桁mod3が、0~2 なので、列挙さえできれば O(|S|)

累積和的に考える?
右端からの累積和を考えよう
0の個数が、そこ右端での答え

dpで行けるかな?

"""

import sys
from sys import stdin

N = int(stdin.readline())

S = list(stdin.readline()[:-1])

mod = 998244353

ans = 0

dp = [0,0,0]

for i in range(N):

    ndp = [0,0,0]

    if S[i] == "?":

        for nc in range(10):
            for k in range(3):
                ndp[ (k+nc) % 3 ] += dp[k]
            ndp[nc % 3] += 1

    else:

        nc = int(S[i])
        for k in range(3):
            ndp[ (k+nc) % 3 ] += dp[k]

        ndp[nc % 3] += 1

    ans += ndp[0]
    ans %= mod
    for j in range(3):
        ndp[j] %= mod
    dp = ndp


print (ans % mod)
    
0