結果

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

ソースコード

diff #

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