結果
問題 |
No.1631 Sorting Integers (Multiple of K) Easy
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:05:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 832 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 338,816 KB |
最終ジャッジ日時 | 2025-06-12 16:05:09 |
合計ジャッジ時間 | 6,170 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 TLE * 1 -- * 17 |
ソースコード
def main(): import sys from functools import lru_cache N, K = map(int, sys.stdin.readline().split()) c = list(map(int, sys.stdin.readline().split())) c = tuple(c) initial_counts = tuple([0] * 9) @lru_cache(maxsize=None) def dp(remainder, counts): if all(ci == ci_initial for ci, ci_initial in zip(counts, c)): return 1 if remainder == 0 else 0 total = 0 for i in range(9): if counts[i] < c[i]: new_counts = list(counts) new_counts[i] += 1 new_counts = tuple(new_counts) new_remainder = (remainder * 10 + (i + 1)) % K total += dp(new_remainder, new_counts) return total result = dp(0, initial_counts) print(result) if __name__ == "__main__": main()