結果
問題 |
No.135 とりあえず1次元の問題
|
ユーザー |
![]() |
提出日時 | 2024-10-08 01:13:00 |
言語 | Common Lisp (sbcl 2.5.0) |
結果 |
AC
|
実行時間 | 96 ms / 5,000 ms |
コード長 | 1,022 bytes |
コンパイル時間 | 129 ms |
コンパイル使用メモリ | 33,512 KB |
実行使用メモリ | 31,888 KB |
最終ジャッジ日時 | 2024-10-08 01:13:02 |
合計ジャッジ時間 | 1,514 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 08 OCT 2024 01:13:00 AM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.010
ソースコード
; 答えの候補を ans = infinity としておく ; N 個の数を降順ソートして (差がプラスになる) ; 隣接項の差を d とし、ans と比較する ; ans のほうが小さければ ans を d に更新する ; 全ての比較終了後 ans = infinity ならば 0 それ以外ならば ans を出力する (defun main () (let* ((n (read)) ; sort 関数に #'> を設定すると降順ソートができる (xs (sort (loop repeat n collect (read)) #'>)) ; most-positive-fixnum は実装上最大の正のfixnum (ans most-positive-fixnum)) (loop for (x y) on xs ; xs の cdr を2項ずつ取り続ける while y ; y が取れなくなるまで for d = (- x y) ; d <- (x - y) 代入 when (> d 0) ; 同じ座標の場合は飛ばす do (setq ans (min ans d))) ; ans を更新する (princ (if (= ans most-positive-fixnum) 0 ans)) (terpri))) (main)