結果
問題 |
No.1631 Sorting Integers (Multiple of K) Easy
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:46:23 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 983 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 325,952 KB |
最終ジャッジ日時 | 2025-06-12 18:46:41 |
合計ジャッジ時間 | 5,540 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 TLE * 1 -- * 17 |
ソースコード
from collections import defaultdict def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 K = int(input[idx]) idx += 1 c = list(map(int, input[idx:idx+9])) idx += 9 original_counts = tuple(c) dp = defaultdict(int) initial_remainder = 0 dp[(initial_remainder, original_counts)] = 1 for _ in range(N): new_dp = defaultdict(int) for (rem, counts), cnt in dp.items(): for d in range(1, 10): if counts[d-1] == 0: continue new_counts_list = list(counts) new_counts_list[d-1] -= 1 new_counts = tuple(new_counts_list) new_rem = (rem * 10 + d) % K new_dp[(new_rem, new_counts)] += cnt dp = new_dp target_counts = tuple([0]*9) answer = dp.get((0, target_counts), 0) print(answer) if __name__ == "__main__": main()