結果
問題 |
No.2001 Distanced Triple
|
ユーザー |
|
提出日時 | 2022-01-31 18:14:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 576 ms / 2,000 ms |
コード長 | 898 bytes |
コンパイル時間 | 314 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 81,868 KB |
最終ジャッジ日時 | 2024-07-02 19:01:30 |
合計ジャッジ時間 | 7,940 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
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()