結果

問題 No.1 道のショートカット
コンテスト
ユーザー Common Lisp
提出日時 2024-11-07 23:33:26
言語 Common Lisp
(sbcl 2.6.9)
コンパイル:
sbclc _filename_
実行:
sbcl --script Main.fasl
結果
AC  
実行時間 13 ms / 5,000 ms
+ 336µs
コード長 1,444 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 47 ms
コンパイル使用メモリ 47,116 KB
実行使用メモリ 29,680 KB
最終ジャッジ日時 2026-10-13 13:14:23
合計ジャッジ時間 2,907 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 13 OCT 2026 01:14:18 PM):

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

ソースコード

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