結果

問題 No.286 Modulo Discount Store
ユーザー Common Lisp
提出日時 2024-11-07 13:50:15
言語 Common Lisp
(sbcl 2.5.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 29,696 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-11-07 13:50:19
合計ジャッジ時間 2,097 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 07 NOV 2024 01:50:15 PM):

; wrote /home/judge/data/code/Main.fasl
; compilation finished in 0:00:00.061

ソースコード

diff #

(defconstant +inf+ 987654321987654321)

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((n (read))
         (m (make-array n :element-type 'integer))
         (2^n (ash 1 n))
         (dp1 (make-array 2^n :initial-element +inf+))
         (dp2 (make-array 2^n :initial-element -1)))
    (setf (aref dp1 0) 0)
    (setf (aref dp2 0) 0)
    (dotimes (i n) (setf (aref m i) (read)))
    (dotimes (i 2^n)
      (dotimes (j n)
        (when (zerop (logand i (ash 1 j)))
              (let ((k (logior i (ash 1 j))))
                (when (= -1 (aref dp2 k))
                      (setf (aref dp2 k) (+ (aref dp2 i) (aref m j))))
                (setf (aref dp1 k) (min (aref dp1 k)
                                        (+ (aref dp1 i)
                                           (max 0 (- (aref m j)
                                                     (mod (aref dp2 i) 1000))))))))))
    (format t "~d~%" (aref dp1 (1- 2^n)))))

(main)
0