結果

問題 No.90 品物の並び替え
ユーザー mikan-watermikan-water
提出日時 2024-01-22 15:13:51
言語 Common Lisp
(sbcl 2.3.8)
結果
TLE  
実行時間 -
コード長 2,030 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 41,380 KB
実行使用メモリ 108,896 KB
最終ジャッジ日時 2024-09-28 06:26:41
合計ジャッジ時間 10,682 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
21,760 KB
testcase_01 AC 1,038 ms
77,056 KB
testcase_02 AC 10 ms
21,888 KB
testcase_03 AC 76 ms
74,752 KB
testcase_04 AC 103 ms
75,008 KB
testcase_05 AC 1,180 ms
77,184 KB
testcase_06 AC 846 ms
76,928 KB
testcase_07 AC 19 ms
30,336 KB
testcase_08 AC 9 ms
21,888 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 28 SEP 2024 06:26:30 AM):

; file: /home/judge/data/code/Main.lisp
; in: DEFUN CALC-SCORE
;     (LENGTH ARY)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::ARY

;     (AREF ARY J)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::ARY

;     (SETF ARY (MAKE-ARRAY (LENGTH L) :INITIAL-CONTENTS L))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::ARY

; 
; caught WARNING:
;   2 more uses of undefined variable ARY


; file: /home/judge/data/code/Main.lisp
; in: DEFUN INPUT-TO-LIST
;     (PUSH (STACK-TO-INT NSTACK) INT-LIST)
; ==>
;   (SETQ INT-LIST (CONS #:ITEM INT-LIST))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::INT-LIST
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::INT-LIST

;     (SETF INT-LIST 'NIL)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::INT-LIST

; 
; caught WARNING:
;   1 more use of undefined variable INT-LIST


; file: /home/judge/data/code/Main.lisp
; in: DEFUN INPUT-SCORES
;     (LOOP FOR ITEM IN L
;           DO (PUSH (LIST (LIST (FIRST ITEM) (SECOND ITEM)) (THIRD ITEM))
;                    *SCORES*))
; --> LET SB-KERNEL:THE* 
; ==>
;   L
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::L

;     (PUSH (INPUT-TO-LIST (READ-LINE)) L)
; ==>
;   (SETQ L (CONS #:ITEM L))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::L

;     (SETF L 'NIL)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::L

; 
; caught WARNING:
;   4 more uses of undefined variable L


; file: /home/judge/data/code/Main.lisp
; in: DEFUN INPUT-TO-LIST
;     (SETF NSTACK NIL)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::NSTACK

;     (STACK-TO-INT NSTACK)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::NSTACK

;     (SETF NSTACK 'NIL)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::NSTACK

; 
; caught WARNING:
;   3 more uses of undefined variable

ソースコード

diff #

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Check all patern
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; variables
(defparameter *n-m* '())
(defparameter *score* 0)
;(defparameter *scores* '())
(defparameter *scores* '(((0 1) 1)
			 ((0 2) 2)
			 ((0 3) 3)
			 ((1 2) 4)
			 ((1 3) 5)
			 ((2 3) 6)
			 ((3 2) 100)
			 ((2 1) 100)
			 ((1 0) 100))
			 )

; functions
(defun stack-to-int (nstack)
  (parse-integer (coerce (reverse nstack) 'string))
  )

(defun input-to-list (str)
  (setf nstack '())
  (setf int-list '())
  ; each character
  (loop for c across str
	do
	(cond
	  ; space
	  ((char= c #\ )
	   (push (stack-to-int nstack) int-list)
	   (setf nstack nil))
	  (t
	    (push c nstack)))
	finally (push (stack-to-int nstack) int-list)
	)
  (reverse int-list)
  )

(defun input-scores ()
  (setf l '())
  (loop repeat (cadr *n-m*)
	do
	(push (input-to-list (read-line)) l)
	)
  (setf *scores* '())
  (loop for item in l
	do
	(push (list (list (first item) (second item))
		    (third item)) *scores*))
  )

(defun input ()
  (setf *n-m* (input-to-list (read-line)))
  (input-scores)
  )

(defun permutation (xs &optional a)
  (cond ((null xs)
	 (setf *score* (max *score* (calc-score (reverse a)))))
	(t
	  (dolist (x xs)
	    (permutation (remove x xs) (cons x a)))))
  )

; (((item1 item2) score) ((item1 item2) score) ...)
; search (a b) and return score
(defun check-score (a b)
  (setf ret 0)
  (loop for item in *scores*
	do
	(if (equal (list a b) (car item))
	  (setf ret (cadr item))
	 )
	)
  ret
  )

(defun calc-score (l)
  (setf ret 0)
  (setf ary (make-array (length l)
			:initial-contents l))
  (loop for item across ary
	for i from 0 to (1- (length ary))
	do
	(loop for j from (1+ i) to (1- (length ary))
	      do
	      (setf ret (+ ret (check-score item (aref ary j))))
	      )
	)
  ret
  )

(defun n90 ()
  (input)

  ; make list from n
  (setf l '())
  (loop for i from 0 to (1- (car *n-m*))
	do
	(push i l)
	)

  ; all permutation
  (permutation l)
  (princ *score*)
  )

(n90)
0