結果
| 問題 |
No.34 砂漠の行商人
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-11-15 03:53:21 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 5,000 ms |
| コード長 | 1,883 bytes |
| コンパイル時間 | 291 ms |
| コンパイル使用メモリ | 41,976 KB |
| 実行使用メモリ | 34,788 KB |
| 最終ジャッジ日時 | 2024-11-15 03:53:23 |
| 合計ジャッジ時間 | 1,916 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 15 NOV 2024 03:53:21 AM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.027
ソースコード
(defparameter +dx+ (make-array 4 :element-type 'integer :initial-contents '(1 0 -1 0)))
(defparameter +dy+ (make-array 4 :element-type 'integer :initial-contents '(0 -1 0 1)))
(defvar *que* (make-array 1010101))
(defvar *que-front* 0)
(defvar *que-back* 0)
(defun main (&rest argv)
(declare (ignorable argv))
(let* ((n (read))
(taro-hp (read))
(start-x (1- (read)))
(start-y (1- (read)))
(goal-x (1- (read)))
(goal-y (1- (read)))
(desert-levels (make-array (list n n) :element-type 'integer))
(dp1 (make-array (list n n) :element-type 'integer :initial-element 0))
(dp2 (make-array (list n n) :element-type 'integer :initial-element 0)))
(dotimes (i n) (dotimes (j n) (setf (aref desert-levels i j) (read))))
(setf (aref dp1 start-y start-x) taro-hp)
(setf (aref *que* *que-front*) (cons start-x start-y))
(incf *que-front*)
(loop while (> *que-front* *que-back*) do
(let* ((now (aref *que* *que-back*))
(x (car now))
(y (cdr now)))
(incf *que-back*)
(dotimes (k 4)
(let ((xx (+ x (aref +dx+ k)))
(yy (+ y (aref +dy+ k))))
(unless (or (or (< xx 0) (<= n xx) (< yy 0) (<= n yy))
(>= (aref dp1 yy xx) (- (aref dp1 y x) (aref desert-levels yy xx))))
(setf (aref dp1 yy xx) (- (aref dp1 y x) (aref desert-levels yy xx))
(aref dp2 yy xx) (1+ (aref dp2 y x))
(aref *que* *que-front*) (cons xx yy))
(incf *que-front*)
(when (and (= xx goal-x) (= yy goal-y))
(format t "~d~%" (aref dp2 yy xx))
(return-from main 0)))))))
(format t "-1~%"))
0)
(main)
Common Lisp