結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2024-11-04 12:20:54 |
言語 | Common Lisp (sbcl 2.5.0) |
結果 |
AC
|
実行時間 | 13 ms / 5,000 ms |
コード長 | 1,491 bytes |
コンパイル時間 | 407 ms |
コンパイル使用メモリ | 35,504 KB |
実行使用メモリ | 32,316 KB |
最終ジャッジ日時 | 2024-11-04 12:20:57 |
合計ジャッジ時間 | 2,433 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 04 NOV 2024 12:20:54 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.012
ソースコード
(defun main (&rest argv) (declare (ignorable argv)) (let* ((n (read)) (dist (make-array 10001 :initial-element 0)) (visited (make-array 10001 :initial-element nil)) (deque (make-array 400000 :element-type 'integer)) (front-index 200000) (rear-index 200000)) (setf (aref visited 1) t) (setf (aref deque rear-index) 1 rear-index (1+ rear-index)) (loop while (< front-index rear-index) do (let* ((p 0) (x (aref deque front-index)) (m x)) (incf front-index) (loop while (/= m 0) do (incf p (logand m 1)) (setf m (ash m -1))) (let ((ip (+ x p)) (im (- x p))) (when (and (<= ip n) (not (aref visited ip))) (setf (aref visited ip) t (aref dist ip) (1+ (aref dist x)) (aref deque rear-index) ip rear-index (1+ rear-index))) (when (and (> im 0) (not (aref visited im))) (setf (aref visited im) t (aref dist im) (1+ (aref dist x)) (aref deque rear-index) im rear-index (1+ rear-index)))))) (format t "~d~%" (if (aref visited n) (1+ (aref dist n)) -1)))) (main)