結果

問題 No.2019 Digits Filling for All Substrings
ユーザー ShirotsumeShirotsume
提出日時 2022-02-03 22:33:10
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 805 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 82,160 KB
最終ジャッジ日時 2023-09-02 19:16:30
合計ジャッジ時間 7,771 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,356 KB
testcase_01 AC 70 ms
71,356 KB
testcase_02 AC 72 ms
71,160 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 73 ms
71,320 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 71 ms
71,584 KB
testcase_23 WA -
testcase_24 AC 199 ms
78,960 KB
testcase_25 AC 253 ms
79,516 KB
testcase_26 AC 160 ms
77,908 KB
testcase_27 AC 94 ms
76,236 KB
testcase_28 AC 93 ms
76,280 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n,s):
    mod = 998244353
    a = [0] * (n + 1)
    for i in range(n):
        if s[i] == '?':
            a[i + 1] += 1
        a[i + 1] += a[i]
    A = [0] * (n + 1)

    for i in range(n + 1):
        A[i] = pow(10, a[i], mod)
    ans = 0
    now = 0
    for i in range(n + 1):
        ans += A[i] * now
        now += pow(A[i], mod - 2, mod)
    ans = (ans - (n + 1) * (n) * pow(2, mod - 2, mod)) * pow(3, mod - 2, mod)
    a = [0] * (n + 1)
    b = [0] * 3
    b[0] = 1
    for i in range(n):
        if s[i] == '?':
            b[0] += 1
            continue
        else: a[i + 1] += int(s[i])
        a[i + 1] += a[i]
        b[a[i + 1] % 3] += 1
    for i in range(3):
        ans += b[i] * (b[i] - 1) // 2
    ans %= mod
    return ans

n = int(input())
s = input()

print(solve(n, s))
0