結果

問題 No.17 2つの地点に泊まりたい
コンテスト
ユーザー Common Lisp
提出日時 2024-11-08 23:25:20
言語 Common Lisp
(sbcl 2.5.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,148 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,162 ms
コンパイル使用メモリ 41,604 KB
実行使用メモリ 28,260 KB
最終ジャッジ日時 2025-12-01 16:19:21
合計ジャッジ時間 2,352 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 01 DEC 2025 04:19:18 PM):

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

ソースコード

diff #
raw source code

(defconstant +inf+ 9876543218987654321)

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((n (read))
         (s (make-array n :element-type 'integer)))
    (dotimes (i n) (setf (aref s i) (read)))
    (let* ((m (read))
           (d (make-array (list n n) :element-type 'integer :initial-element +inf+))
           (res +inf+))
      (dotimes (i n) (setf (aref d i i) 0))
      (dotimes (i m)
        (let* ((a (read))
               (b (read))
               (c (read)))
          (setf (aref d a b) c
                (aref d b a) c)))
      (dotimes (i n)
        (dotimes (j n)
          (dotimes (k n)
            (setf (aref d j k)
                  (min (aref d j k)
                       (+ (aref d j i)
                          (aref d i k)))))))
      (loop for i from 1 below (1- n) do
            (loop for j from 1 below (1- n) do
                  (unless (= i j)
                          (setq res (min res (+ (aref d 0 i)
                                                (aref s i) (aref d i j)
                                                (aref s j) (aref d j (1- n))))))))
      (format t "~d~%" res))))

(main)
0