結果
問題 |
No.1631 Sorting Integers (Multiple of K) Easy
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:21:53 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 942 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,540 KB |
実行使用メモリ | 467,832 KB |
最終ジャッジ日時 | 2025-04-15 23:23:45 |
合計ジャッジ時間 | 6,048 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 11 TLE * 1 -- * 16 |
ソースコード
from collections import defaultdict n, k = map(int, input().split()) c = list(map(int, input().split())) if k == 0: print(0) exit() pow10 = [pow(10, (n - 1 - m), k) for m in range(n)] # Initialize DP with initial state: all counts 0, remainder 0 dp = defaultdict(int) initial_counts = tuple([0] * 9) dp[(initial_counts, 0)] = 1 for m in range(n): next_dp = defaultdict(int) for (counts, rem), cnt in dp.items(): for d in range(9): if counts[d] < c[d]: new_counts = list(counts) new_counts[d] += 1 new_counts_tuple = tuple(new_counts) contribution = (d + 1) * pow10[m] new_rem = (rem + contribution) % k next_dp[(new_counts_tuple, new_rem)] += cnt dp = next_dp # Sum all states where remainder is 0 result = 0 for (counts, rem), cnt in dp.items(): if rem == 0: result += cnt print(result)