結果

問題 No.2019 Digits Filling for All Substrings
ユーザー 👑 H20H20
提出日時 2022-07-22 22:46:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,464 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 130,428 KB
最終ジャッジ日時 2023-09-17 11:19:06
合計ジャッジ時間 12,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,496 KB
testcase_01 AC 71 ms
71,360 KB
testcase_02 AC 73 ms
71,396 KB
testcase_03 AC 71 ms
71,188 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 73 ms
71,508 KB
testcase_21 WA -
testcase_22 AC 70 ms
71,392 KB
testcase_23 AC 70 ms
71,500 KB
testcase_24 AC 396 ms
100,156 KB
testcase_25 AC 530 ms
110,364 KB
testcase_26 AC 301 ms
93,236 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def count(s):
    a = s
    n = len(a)
    ret = 0
    i = 0
    while i<n and a[i]=='?':
        ret+=1
        i+=1

    #配列は末から
    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])
                if leading0==0 and d==0:
                    continue
                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])%mod
    return ret%mod

print(count(S))
0