結果

問題 No.90 品物の並び替え
ユーザー mikan-watermikan-water
提出日時 2024-01-22 15:13:51
言語 Common Lisp
(sbcl 2.3.8)
結果
TLE  
実行時間 -
コード長 2,030 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 39,544 KB
実行使用メモリ 108,568 KB
最終ジャッジ日時 2024-01-22 15:14:03
合計ジャッジ時間 11,272 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
29,472 KB
testcase_01 AC 1,100 ms
86,088 KB
testcase_02 AC 10 ms
29,344 KB
testcase_03 AC 78 ms
84,296 KB
testcase_04 AC 108 ms
84,296 KB
testcase_05 AC 1,230 ms
86,088 KB
testcase_06 AC 886 ms
86,088 KB
testcase_07 AC 19 ms
39,100 KB
testcase_08 AC 10 ms
29,344 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 22 JAN 2024 06:13:51 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