結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-11-09 03:09:46 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 938 bytes |
| コンパイル時間 | 243 ms |
| コンパイル使用メモリ | 29,184 KB |
| 実行使用メモリ | 21,888 KB |
| 最終ジャッジ日時 | 2024-11-09 03:09:47 |
| 合計ジャッジ時間 | 923 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 09 NOV 2024 03:09:45 AM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.042
ソースコード
(defun f (b n dp scores)
(if (/= -1 (aref dp b))
(aref dp b)
(let ((m 0))
(dotimes (i n)
(unless (zerop (logand 1 (ash b (- i))))
(let ((s (f (logxor b (ash 1 i)) n dp scores)))
(dotimes (j n)
(incf s (* (logand 1 (ash b (- j))) (aref scores (+ j (* i n))))))
(setf m (max m s)))))
(setf (aref dp b) m)
m)))
(defun main (&rest argv)
(declare (ignorable argv))
(let* ((n (read))
(m (read))
(scores (make-array (* n n)))
(dp (make-array (ash 1 n) :element-type 'integer :initial-element -1))
(res 0))
(dotimes (i m)
(let* ((item1 (read))
(item2 (read))
(score (read)))
(setf (aref scores (+ (* item1 n) item2)) score)))
(setf (aref dp 0) 0)
(setq res (f (1- (ash 1 n)) n dp scores))
(format t "~d~%" res)))
(main)
Common Lisp