結果

問題 No.2001 Distanced Triple
ユーザー to-omerto-omer
提出日時 2022-01-31 18:14:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 611 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 85,840 KB
最終ジャッジ日時 2023-09-15 16:38:08
合計ジャッジ時間 9,778 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
76,204 KB
testcase_01 AC 111 ms
76,276 KB
testcase_02 AC 520 ms
83,796 KB
testcase_03 AC 323 ms
82,396 KB
testcase_04 AC 316 ms
82,812 KB
testcase_05 AC 309 ms
81,740 KB
testcase_06 AC 102 ms
72,180 KB
testcase_07 AC 362 ms
82,992 KB
testcase_08 AC 101 ms
72,480 KB
testcase_09 AC 101 ms
72,184 KB
testcase_10 AC 611 ms
84,104 KB
testcase_11 AC 102 ms
72,180 KB
testcase_12 AC 102 ms
72,492 KB
testcase_13 AC 101 ms
72,472 KB
testcase_14 AC 100 ms
72,472 KB
testcase_15 AC 102 ms
72,176 KB
testcase_16 AC 103 ms
72,488 KB
testcase_17 AC 107 ms
72,528 KB
testcase_18 AC 100 ms
72,400 KB
testcase_19 AC 102 ms
72,480 KB
testcase_20 AC 102 ms
72,488 KB
testcase_21 AC 389 ms
85,840 KB
testcase_22 AC 271 ms
81,948 KB
testcase_23 AC 104 ms
72,636 KB
testcase_24 AC 101 ms
72,544 KB
testcase_25 AC 265 ms
81,764 KB
testcase_26 AC 279 ms
82,420 KB
testcase_27 AC 603 ms
84,968 KB
testcase_28 AC 578 ms
85,828 KB
testcase_29 AC 99 ms
72,176 KB
testcase_30 AC 100 ms
72,488 KB
testcase_31 AC 593 ms
83,780 KB
testcase_32 AC 586 ms
84,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
from itertools import product

MOD = 998244353


@lru_cache(None)
def solve(L, R, A, B, C):
    if L + max(A + B, C) > R:
        return 0
    if L >= R:
        return int(L == R and A == 0 and B == 0 and C == 0)
    res = 0
    for (x0, y0, z0) in product(range(10), repeat=3):
        # L<=x
        nL, L0 = divmod(L, 10)
        nL += L0 > x0
        # x+A<=y
        nA, A0 = divmod(x0 + A, 10)
        nA += A0 > y0
        # y+B<=z
        nB, B0 = divmod(y0 + B, 10)
        nB += B0 > z0
        # x+C<=z
        nC, C0 = divmod(x0 + C, 10)
        nC += C0 > z0
        # z<=R
        nR, R0 = divmod(R, 10)
        nR -= z0 > R0
        res += solve(nL, nR, nA, nB, nC)
    return res % MOD


def main():
    L, R = map(int, input().split())
    A, B, C = map(int, input().split())
    print(solve(L, R, A, B, C))


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