結果
問題 |
No.1634 Sorting Integers (Multiple of K) Hard
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:49:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,024 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 268,428 KB |
最終ジャッジ日時 | 2025-03-31 17:50:37 |
合計ジャッジ時間 | 7,916 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 TLE * 1 -- * 23 |
ソースコード
import sys from collections import defaultdict def main(): N, K = map(int, sys.stdin.readline().split()) c = list(map(int, sys.stdin.readline().split())) counts = tuple(c) dp = defaultdict(int) dp[(counts, 0)] = 1 # Initial state: all counts available, remainder 0 for _ in range(N): next_dp = defaultdict(int) for (current_counts, rem), cnt in dp.items(): for d in range(1, 10): idx = d - 1 if current_counts[idx] == 0: continue new_counts = list(current_counts) new_counts[idx] -= 1 new_counts_tuple = tuple(new_counts) new_rem = (rem * 10 + d) % K next_dp[(new_counts_tuple, new_rem)] += cnt dp = next_dp # Update to next step's states # After N steps, check for all digits used and remainder 0 final_counts = tuple([0] * 9) print(dp.get((final_counts, 0), 0)) if __name__ == "__main__": main()