結果

問題 No.1 道のショートカット
コンテスト
ユーザー Common Lisp
提出日時 2024-11-07 23:33:26
言語 Common Lisp
(sbcl 2.6.3)
コンパイル:
sbclc _filename_
実行:
sbcl --script Main.fasl
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,444 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 905 ms
コンパイル使用メモリ 38,528 KB
実行使用メモリ 22,656 KB
最終ジャッジ日時 2026-05-08 06:57:35
合計ジャッジ時間 2,850 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 08 MAY 2026 06:57:32 AM):

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

ソースコード

diff #
raw source code

(defconstant +inf+ 9876543210)

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((n (read))
         (c (read))
         (v (read))
         (ss (make-array v :element-type 'integer))
         (tt (make-array v :element-type 'integer))
         (yy (make-array v :element-type 'integer))
         (mm (make-array v :element-type 'integer))
         (dp (make-array (list n (1+ c)) :initial-element +inf+))
         (graph (make-array n :element-type 'list :initial-element nil)))
    (dotimes (i v) (setf (aref ss i) (1- (read))))
    (dotimes (i v) (setf (aref tt i) (1- (read))))
    (dotimes (i v) (setf (aref yy i) (read)))
    (dotimes (i v) (setf (aref mm i) (read)))
    (dotimes (i v) (push (list (aref tt i) (aref yy i) (aref mm i)) (aref graph (aref ss i))))
    (setf (aref dp 0 c) 0)
    (loop for i below (1- n) do
          (loop for j to c do
                (when (< (aref dp i j) +inf+)
                      (dolist (pqr (aref graph i))
                        (let ((p (first pqr))
                              (q (second pqr))
                              (r (third pqr)))
                          (when (>= (- j q) 0)
                                (setf (aref dp p (- j q)) (min (aref dp p (- j q)) (+ r (aref dp i j))))))))))
    (let ((res (loop for i to c minimize (aref dp (1- n) i))))
      (format t "~d~%" (if (< res +inf+)
                           res
                           -1)))))

(main)
0