結果

問題 No.2019 Digits Filling for All Substrings
ユーザー titiatitia
提出日時 2022-07-25 02:04:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 608 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 10,760 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2023-09-21 03:24:07
合計ジャッジ時間 10,210 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,920 KB
testcase_01 AC 16 ms
7,752 KB
testcase_02 AC 16 ms
7,816 KB
testcase_03 AC 16 ms
7,816 KB
testcase_04 AC 379 ms
8,512 KB
testcase_05 AC 268 ms
8,388 KB
testcase_06 AC 240 ms
8,356 KB
testcase_07 AC 177 ms
8,196 KB
testcase_08 AC 589 ms
8,492 KB
testcase_09 AC 608 ms
8,576 KB
testcase_10 AC 599 ms
8,480 KB
testcase_11 AC 607 ms
8,552 KB
testcase_12 AC 595 ms
8,472 KB
testcase_13 AC 597 ms
8,608 KB
testcase_14 AC 21 ms
7,724 KB
testcase_15 AC 21 ms
7,820 KB
testcase_16 AC 45 ms
7,672 KB
testcase_17 AC 23 ms
7,828 KB
testcase_18 AC 24 ms
7,756 KB
testcase_19 AC 15 ms
7,672 KB
testcase_20 AC 16 ms
7,816 KB
testcase_21 AC 15 ms
7,760 KB
testcase_22 AC 16 ms
7,900 KB
testcase_23 AC 16 ms
7,816 KB
testcase_24 AC 299 ms
8,436 KB
testcase_25 AC 448 ms
8,384 KB
testcase_26 AC 222 ms
8,296 KB
testcase_27 AC 51 ms
7,796 KB
testcase_28 AC 49 ms
8,308 KB
testcase_29 AC 386 ms
8,348 KB
testcase_30 AC 546 ms
8,452 KB
testcase_31 AC 530 ms
8,384 KB
testcase_32 AC 172 ms
8,280 KB
testcase_33 AC 401 ms
8,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
S=input().strip()
mod=998244353

if S[0]=="?":
    DP=[4,3,3]
else:
    x=int(S[0])
    DP=[0,0,0]
    DP[x%3]=1

ANS=0
for s in S[1:]:
    ANS+=DP[0]
    ANS%=mod
    if s=="?":
        NDP=[4,3,3]

        for i in range(3):
            NDP[i]+=DP[i]*4
            NDP[(i+1)%3]+=DP[i]*3
            NDP[(i+2)%3]+=DP[i]*3
    else:
        x=int(s)
        NDP=[0,0,0]

        NDP[x%3]=1

        for i in range(3):
            NDP[(i+x)%3]+=DP[i]

    for i in range(3):
        DP[i]=NDP[i]%mod

print((ANS+DP[0])%mod)
0