結果

問題 No.2803 Bocching Star
ユーザー Lisp_CoderLisp_Coder
提出日時 2024-07-21 01:16:10
言語 Common Lisp
(sbcl 2.3.8)
結果
RE  
実行時間 -
コード長 1,563 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 26,112 KB
最終ジャッジ日時 2024-07-21 01:16:13
合計ジャッジ時間 2,424 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 21 JUL 2024 01:16:10 AM):

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

ソースコード

diff #

(defun read-integers ()
  (with-open-file (stream *standard-input* :direction :input :external-format :utf-8)
    (loop for line = (read-line stream nil)
          while line
          append (mapcar #'parse-integer (split-sequence-from-string line)))))

(defun split-sequence-from-string (str)
  (let ((start 0)
        (len (length str))
        (result '()))
    (loop for i from 0 to len
          when (or (eql i len) (char= (char str i) #\Space))
          do (when (> i start)
               (push (parse-integer (subseq str start i)) result))
             (setf start (1+ i)))
    (nreverse result)))

(defun main ()
  (let* ((data (read-integers))
         (N (first data))
         (S (second data))
         (P (subseq data 2 (+ 2 N)))
         (indexed-P (loop for i from 0 below N collect (cons (nth i P) (1+ i))))
         (sorted-P (sort (copy-list indexed-P) #'< :key #'car))
         (result '()))
    (loop for i from 0 below N
          for (val . idx) = (nth i sorted-P)
          for left-diff = (if (> i 0) (- val (car (nth (1- i) sorted-P))) most-positive-fixnum)
          for right-diff = (if (< i (1- N)) (- (car (nth (1+ i) sorted-P)) val) most-positive-fixnum)
          for near = (min left-diff right-diff)
          when (> near S)
          do (push idx result))
    (setf result (sort result #'<))
    (with-open-file (stream *standard-output* :direction :output :external-format :utf-8)
      (format stream "~d~%" (length result))
      (dolist (elem result)
        (format stream "~d " elem))
      (terpri stream))))

(main)
0