結果
| 問題 |
No.1631 Sorting Integers (Multiple of K) Easy
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:54:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 832 bytes |
| コンパイル時間 | 426 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 82,588 KB |
| 最終ジャッジ日時 | 2025-06-12 20:57:53 |
| 合計ジャッジ時間 | 6,241 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 TLE * 1 -- * 17 |
ソースコード
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()
gew1fw