結果

問題 No.2302 Carry X Times
ユーザー ShirotsumeShirotsume
提出日時 2023-04-03 01:40:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 81,872 KB
実行使用メモリ 78,956 KB
最終ジャッジ日時 2023-10-25 05:17:39
合計ジャッジ時間 7,076 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
76,560 KB
testcase_01 AC 104 ms
76,108 KB
testcase_02 AC 130 ms
76,896 KB
testcase_03 AC 42 ms
55,452 KB
testcase_04 AC 42 ms
55,452 KB
testcase_05 AC 58 ms
66,184 KB
testcase_06 AC 59 ms
68,228 KB
testcase_07 AC 58 ms
66,184 KB
testcase_08 AC 55 ms
66,324 KB
testcase_09 AC 61 ms
68,388 KB
testcase_10 AC 370 ms
78,956 KB
testcase_11 AC 346 ms
78,636 KB
testcase_12 AC 369 ms
78,772 KB
testcase_13 AC 322 ms
78,612 KB
testcase_14 AC 363 ms
78,864 KB
testcase_15 AC 250 ms
77,516 KB
testcase_16 AC 234 ms
77,316 KB
testcase_17 AC 349 ms
78,932 KB
testcase_18 AC 278 ms
77,844 KB
testcase_19 AC 291 ms
78,284 KB
testcase_20 AC 303 ms
78,036 KB
testcase_21 AC 316 ms
78,748 KB
testcase_22 AC 273 ms
77,684 KB
testcase_23 AC 293 ms
78,344 KB
testcase_24 AC 257 ms
77,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
d = {}
def f(na, nb, x, c):
    if (na, nb, x, c) in d:
        return d[na, nb, x, c]
    ans = 0
    if na == nb == 0:
        if x == 0:
            ans = 1
        else:
            ans = 0
    else:
        for a in range(min(na + 1, 10)):
            for b in range(min(nb + 1, 10)):
                if a + b + c < 10:
                    ans += f((na - a) // 10, (nb - b) // 10, x, 0)
                elif x > 0:
                    ans += f((na - a) // 10, (nb - b) // 10, x - 1, 1)
    d[na,nb,x,c] = ans % mod
    return d[na,nb,x,c]

def dsum(x):
    ans = 0
    while x > 0:
        ans += x % 10
        x //= 10
    return ans
for _ in range(ii()):
    n, x = mi()
    print(f(n, n, x, 0))
0