結果

問題 No.2019 Digits Filling for All Substrings
ユーザー 👑 H20H20
提出日時 2022-07-22 23:11:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 672 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 130,648 KB
最終ジャッジ日時 2023-09-17 12:02:59
合計ジャッジ時間 12,352 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,320 KB
testcase_01 AC 78 ms
71,592 KB
testcase_02 AC 79 ms
71,432 KB
testcase_03 AC 77 ms
71,364 KB
testcase_04 AC 434 ms
112,412 KB
testcase_05 AC 337 ms
102,076 KB
testcase_06 AC 308 ms
99,188 KB
testcase_07 AC 254 ms
93,120 KB
testcase_08 AC 587 ms
130,040 KB
testcase_09 AC 636 ms
130,500 KB
testcase_10 AC 651 ms
130,112 KB
testcase_11 AC 657 ms
130,484 KB
testcase_12 AC 644 ms
130,632 KB
testcase_13 AC 653 ms
130,648 KB
testcase_14 AC 121 ms
78,048 KB
testcase_15 AC 120 ms
78,132 KB
testcase_16 AC 147 ms
80,528 KB
testcase_17 AC 122 ms
78,392 KB
testcase_18 AC 125 ms
78,316 KB
testcase_19 AC 76 ms
71,472 KB
testcase_20 AC 77 ms
71,464 KB
testcase_21 AC 76 ms
71,060 KB
testcase_22 AC 77 ms
71,548 KB
testcase_23 AC 77 ms
71,380 KB
testcase_24 AC 402 ms
100,156 KB
testcase_25 AC 538 ms
110,392 KB
testcase_26 AC 309 ms
93,168 KB
testcase_27 AC 131 ms
81,464 KB
testcase_28 AC 129 ms
81,284 KB
testcase_29 AC 502 ms
107,916 KB
testcase_30 AC 672 ms
120,864 KB
testcase_31 AC 651 ms
120,036 KB
testcase_32 AC 286 ms
90,276 KB
testcase_33 AC 516 ms
109,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def count(s):
    a = s
    n = len(a)
    ret = 0
    i = 0

    #配列は末から
    dp=[[[0] * 3 for _ in range(2)] for _ in range(n+1) ]
    dp[0][1][0] = 1

    #条件に合わせてDP
    for i in range(n) :
        for leading0, mod3 in product(range(2), range(3)):
            if a[i]=='?':
                max_d = 9
                for d in range(max_d+1):
                    mod3_ = (mod3*10 + d) % 3
                    leading0_ = leading0 and d==0
                    dp[i + 1][leading0_][mod3_] = (dp[i + 1][leading0_][mod3_]+dp[i][leading0][mod3])%mod
            else:
                d = int(a[i])
                leading0_ = leading0 and d==0
                mod3_ = (mod3*10 + d) % 3
                dp[i + 1][leading0_][mod3_] = (dp[i + 1][leading0_][mod3_]+dp[i][leading0][mod3])%mod
        if i>=1:
            if a[i]=='?':
                max_d = 9
                for d in range(max_d+1):
                    mod3_ = d % 3
                    leading0_ = d==0
                    dp[i + 1][0][mod3_] += 1
            else:
                d = int(a[i])
                mod3_ = d % 3
                leading0_ = d==0
                dp[i + 1][0][mod3_] += 1
        ret = (ret+dp[i+1][0][0]+dp[i+1][1][0])%mod
    return ret%mod

print(count(S))
0