結果

問題 No.2019 Digits Filling for All Substrings
ユーザー 👑 tamatotamato
提出日時 2022-07-22 22:55:56
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,184 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 77,632 KB
最終ジャッジ日時 2023-09-17 11:31:41
合計ジャッジ時間 5,335 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,228 KB
testcase_01 AC 74 ms
71,164 KB
testcase_02 AC 70 ms
71,424 KB
testcase_03 AC 71 ms
71,336 KB
testcase_04 AC 125 ms
77,308 KB
testcase_05 AC 116 ms
77,180 KB
testcase_06 AC 117 ms
77,052 KB
testcase_07 AC 108 ms
77,320 KB
testcase_08 AC 141 ms
77,532 KB
testcase_09 AC 143 ms
77,600 KB
testcase_10 AC 148 ms
77,476 KB
testcase_11 AC 150 ms
77,384 KB
testcase_12 AC 154 ms
77,520 KB
testcase_13 AC 154 ms
77,632 KB
testcase_14 AC 92 ms
76,660 KB
testcase_15 AC 92 ms
76,592 KB
testcase_16 AC 104 ms
77,396 KB
testcase_17 AC 94 ms
76,532 KB
testcase_18 AC 96 ms
76,532 KB
testcase_19 AC 72 ms
71,088 KB
testcase_20 AC 72 ms
71,436 KB
testcase_21 AC 71 ms
71,272 KB
testcase_22 AC 70 ms
71,096 KB
testcase_23 AC 70 ms
71,440 KB
testcase_24 AC 102 ms
76,768 KB
testcase_25 AC 112 ms
76,704 KB
testcase_26 AC 96 ms
76,792 KB
testcase_27 AC 83 ms
76,232 KB
testcase_28 AC 82 ms
76,344 KB
testcase_29 AC 122 ms
77,216 KB
testcase_30 AC 136 ms
77,480 KB
testcase_31 AC 134 ms
77,532 KB
testcase_32 AC 105 ms
77,388 KB
testcase_33 AC 122 ms
77,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')

    ans = 0
    for m in range(3):
        dp = [0] * 3
        for i, s in enumerate(S):
            dp_new = [0] * 3
            if s == "?":
                if m:
                    #ans = (ans + 3) % mod
                    dp_new[m] = 3
                else:
                    #ans = (ans + 4) % mod
                    dp_new[m] = 4
                for j in range(3):
                    dp_new[j] = (dp_new[j] + (dp[j] * 4)%mod) % mod
                    dp_new[(j+1)%3] = (dp_new[(j+1)%3] + (dp[j] * 3) % mod) % mod
                    dp_new[(j+2)%3] = (dp_new[(j+2)%3] + (dp[j] * 3) % mod) % mod
            else:
                s = int(s)
                if s % 3 == m:
                    #ans += 1
                    #ans %= mod
                    dp_new[m] = 1
                for j in range(3):
                    dp_new[(j + s) % 3] = (dp_new[(j + s) % 3] + dp[j])%mod
            dp = dp_new
            #print(m, dp)
            ans = (ans + dp[0])%mod
        #print(m, ans)
    print(ans)


if __name__ == '__main__':
    main()
0