結果

問題 No.2019 Digits Filling for All Substrings
ユーザー siganaisiganai
提出日時 2022-07-22 22:28:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,135 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 100,864 KB
最終ジャッジ日時 2023-09-17 10:54:09
合計ジャッジ時間 7,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
78,812 KB
testcase_01 WA -
testcase_02 AC 142 ms
79,032 KB
testcase_03 WA -
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 AC 146 ms
78,880 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 143 ms
78,776 KB
testcase_24 AC 159 ms
80,772 KB
testcase_25 AC 163 ms
81,152 KB
testcase_26 AC 156 ms
80,728 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353

import sys
input=sys.stdin.readline

n = int(input())
s = input().rstrip()
dp = [[0] * 3 for _ in range(n+1)]
ans = 0
for i in range(n):
    if s[i] == '?':
        ans += 4
        ans += dp[i][0] * 4
        ans += dp[i][1] * 3
        ans += dp[i][2] * 3
        ans %= mod
        dp[i+1][0] = (dp[i][0] * 4 + dp[i][1] * 3 + dp[i][2] * 3 + 4) % mod
        dp[i+1][1] = (dp[i][0] * 3 + dp[i][1] * 4 + dp[i][2] * 3 + 3) % mod
        dp[i+1][2] = (dp[i][0] * 3 + dp[i][1] * 3 + dp[i][2] * 4 + 3) % mod
    else:
        si = int(s[i])
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
        dp[i+1][2] = dp[i][2]
        if si % 3 == 0:
            ans += 1
            ans += dp[i][0]
            dp[i+1][0] += 1
        elif si % 3 == 1:
            ans += dp[i][2]
            dp[i+1][1] += 1
        else:
            ans += dp[i][1]
            dp[i+1][2] += 1
        ans %= mod

print(ans)
0