結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー gew1fw
提出日時 2025-06-12 13:31:00
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 983 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 327,480 KB
最終ジャッジ日時 2025-06-12 13:36:06
合計ジャッジ時間 5,991 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0