結果

問題 No.2019 Digits Filling for All Substrings
ユーザー 👑 H20H20
提出日時 2022-07-22 22:57:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 97,584 KB
最終ジャッジ日時 2023-09-17 11:36:16
合計ジャッジ時間 6,585 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,152 KB
testcase_01 AC 74 ms
71,332 KB
testcase_02 AC 73 ms
71,376 KB
testcase_03 AC 74 ms
71,236 KB
testcase_04 AC 160 ms
90,868 KB
testcase_05 AC 142 ms
86,876 KB
testcase_06 AC 134 ms
85,520 KB
testcase_07 AC 126 ms
83,356 KB
testcase_08 AC 195 ms
97,584 KB
testcase_09 AC 217 ms
97,544 KB
testcase_10 AC 220 ms
97,248 KB
testcase_11 AC 217 ms
97,472 KB
testcase_12 AC 221 ms
97,408 KB
testcase_13 AC 219 ms
97,564 KB
testcase_14 AC 93 ms
76,464 KB
testcase_15 AC 93 ms
76,708 KB
testcase_16 AC 100 ms
78,124 KB
testcase_17 AC 91 ms
76,588 KB
testcase_18 AC 94 ms
76,376 KB
testcase_19 AC 74 ms
71,280 KB
testcase_20 AC 73 ms
71,264 KB
testcase_21 AC 74 ms
71,336 KB
testcase_22 AC 74 ms
71,156 KB
testcase_23 AC 73 ms
71,392 KB
testcase_24 AC 165 ms
86,204 KB
testcase_25 AC 200 ms
89,756 KB
testcase_26 AC 141 ms
82,920 KB
testcase_27 AC 85 ms
76,608 KB
testcase_28 AC 87 ms
76,580 KB
testcase_29 AC 195 ms
89,112 KB
testcase_30 AC 237 ms
94,084 KB
testcase_31 AC 234 ms
93,764 KB
testcase_32 AC 138 ms
82,000 KB
testcase_33 AC 200 ms
89,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import product
n = int(input())
S = input()
mod = 998244353

def count(s):
    a = s
    n = len(a)
    ret = 0
    #配列は末から
    dp=[[0] * 3 for _ in range(n+1) ]
    for i in range(n) :
        if a[i]=='?':
            max_d = 9
            for d in range(max_d+1):
                mod3_ = d % 3
                dp[i + 1][mod3_] += 1
        else:
            d = int(a[i])
            mod3_ = d % 3
            dp[i + 1][mod3_] += 1
        #条件に合わせてDP
        for mod3 in range(3):
            if a[i]=='?':
                max_d = 9
                for d in range(max_d+1):
                    mod3_ = (mod3*10 + d) % 3
                    dp[i + 1][mod3_] = (dp[i + 1][mod3_]+dp[i][mod3])%mod
            else:
                d = int(a[i])
                mod3_ = (mod3*10 + d) % 3
                dp[i + 1][mod3_] = (dp[i + 1][mod3_]+dp[i][mod3])%mod
        ret = (ret+dp[i+1][0])%mod
    return ret%mod

print(count(S))
0