結果
問題 | No.2803 Bocching Star |
ユーザー | Lisp_Coder |
提出日時 | 2024-07-21 01:11:49 |
言語 | Common Lisp (sbcl 2.3.8) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,575 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 30,592 KB |
実行使用メモリ | 28,416 KB |
最終ジャッジ日時 | 2024-07-21 01:11:52 |
合計ジャッジ時間 | 2,409 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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:11:49 AM): ; file: /home/judge/data/code/Main.lisp ; in: DEFUN MAIN ; (SORT INDEXED-P #'< :KEY #'CAR) ; ; caught STYLE-WARNING: ; The return value of STABLE-SORT-LIST should not be discarded. ; (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 # I))) ; (SORTED-P (SORT INDEXED-P #'< :KEY #'CAR)) ; (PARENT (CAR (UNION-FIND-MAKE N))) ; (RANK (CADR (UNION-FIND-MAKE N))) ; (RESULT 'NIL)) ; (LOOP FOR I FROM 0 BELOW (1- N) ; FOR (VAL1 . IDX1) = (NTH I SORTED-P) ; FOR ...) ; (LOOP FOR I FROM 0 BELOW N ; FOR ROOT = (UNION-FIND-FIND PARENT I) ; IF ...) ; (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))) ; ; note: deleting unreachable code ; (CAR (UNION-FIND-MAKE N)) ; ; caught WARNING: ; Derived type of (COMMON-LISP-USER::UNION-FIND-MAKE COMMON-LISP-USER::N) is ; (VALUES (SIMPLE-ARRAY T) SIMPLE-VECTOR &OPTIONAL), ; conflicting with its asserted type ; LIST. ; See also: ; The SBCL Manual, Node "Handling of Types" ; file: /home/judge/data/code/Main.lisp ; in: DEFUN READ-INTEGERS ; (SPLIT-SEQUENCE #\ LINE :REMOVE-EMPTY-SUBSEQS T) ; ; caught STYLE-WARNING: ; undefined function: COMMON-LISP-USER::SPLIT-SEQUENCE ; ; compilation unit finished ; Undefined function: ; SPLIT-SEQUENCE ; caught 1 WARNING condition ; caught 2 STYLE-WARNING conditions ; printed 1 note ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.019
ソースコード
#-swank (unless (member :child-sbcl *features*) (quit :recklessly-p t :unix-status (process-exit-code (run-program *runtime-pathname* `("--control-stack-size" "1024MB" "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options" "--eval" "(push :child-sbcl *features*)" "--script" ,(namestring *load-pathname*)) :output t :error t :input t)))) (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 (map 'list #'parse-integer (split-sequence #\Space line :remove-empty-subseqs t))))) (defun union-find-make (n) (let ((parent (make-array n :initial-contents (loop for i from 0 below n collect i))) (rank (make-array n :initial-element 0))) (values parent rank))) (defun union-find-find (parent x) (if (/= (aref parent x) x) (setf (aref parent x) (union-find-find parent (aref parent x)))) (aref parent x)) (defun union-find-union (parent rank x y) (let ((root-x (union-find-find parent x)) (root-y (union-find-find parent y))) (unless (= root-x root-y) (cond ((> (aref rank root-x) (aref rank root-y)) (setf (aref parent root-y) root-x)) ((< (aref rank root-x) (aref rank root-y)) (setf (aref parent root-x) root-y)) (t (setf (aref parent root-y) root-x) (incf (aref rank root-x))))))) (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) i))) (sorted-P (sort indexed-P #'< :key #'car)) (parent (car (union-find-make N))) (rank (cadr (union-find-make N))) (result '())) (loop for i from 0 below (1- N) for (val1 . idx1) = (nth i sorted-P) for (val2 . idx2) = (nth (1+ i) sorted-P) when (<= (- val2 val1) S) do (union-find-union parent rank idx1 idx2)) (loop for i from 0 below N for root = (union-find-find parent i) if (= root i) do (push (1+ i) 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)