結果
問題 |
No.527 ナップサック容量問題
|
ユーザー |
![]() |
提出日時 | 2024-11-14 21:05:08 |
言語 | Common Lisp (sbcl 2.5.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 1,677 ms |
コンパイル使用メモリ | 37,364 KB |
実行使用メモリ | 32,276 KB |
最終ジャッジ日時 | 2024-11-14 21:05:19 |
合計ジャッジ時間 | 4,060 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 14 NOV 2024 09:05:15 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.048
ソースコード
(defun main (&rest argv) (declare (ignorable argv)) (let* ((n (read)) (v (make-array n :element-type 'integer)) (w (make-array n :element-type 'integer)) (s 0) (dp (make-array 101010 :element-type 'integer :initial-element 0))) (dotimes (i n) (let* ((vi (read)) (wi (read))) (setf (aref v i) vi (aref w i) wi s (+ s wi)))) (let* ((v-max (read))) (dotimes (i n) (loop for j from (1+ s) downto (aref w i) do (setf (aref dp j) (max (aref dp j) (+ (aref dp (- j (aref w i))) (aref v i)))))) (dotimes (i s) (when (= v-max (aref dp (1+ i))) (format t "~d~%" (1+ i)) (return))) (if (= v-max (aref dp (1+ s))) (format t "inf~%") (loop for i from s downto 1 do (when (= v-max (aref dp i)) (format t "~d~%" i) (return))))))) (main)