結果

問題 No.90 品物の並び替え
ユーザー mikan-watermikan-water
提出日時 2024-01-25 09:51:47
言語 Common Lisp
(sbcl 2.3.8)
結果
AC  
実行時間 1,227 ms / 5,000 ms
コード長 1,605 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 35,760 KB
実行使用メモリ 74,880 KB
最終ジャッジ日時 2024-09-28 07:15:39
合計ジャッジ時間 2,302 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
29,756 KB
testcase_01 AC 118 ms
30,464 KB
testcase_02 AC 10 ms
21,632 KB
testcase_03 AC 21 ms
23,040 KB
testcase_04 AC 22 ms
22,912 KB
testcase_05 AC 117 ms
30,464 KB
testcase_06 AC 118 ms
30,336 KB
testcase_07 AC 11 ms
21,760 KB
testcase_08 AC 10 ms
21,888 KB
testcase_09 AC 1,227 ms
74,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 28 SEP 2024 07:15:36 AM):

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

; 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 (SETF (AREF *ITEMS* (FIRST ITEM) (SECOND ITEM)) (THIRD ITEM)))
; --> 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

; 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 NSTACK


; file: /home/judge/data/code/Main.lisp
; in: DEFUN SCORE-LIST
;     (+ RET (AREF *ITEMS* I1 I2))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::RET

;     (SETF RET (+ RET (AREF *ITEMS* I1 I2)))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::RET

;     (SETF RET 0)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::RET

; 
; caught WARNING:
;   1 more use of undefined variable RET

ソースコード

diff #

; variables
(defparameter *score* 0)
(defparameter *n-m* '(4 9))
(defparameter *items* (make-array '(10 10)
				  :initial-element 0))

; 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
	(setf (aref *items* (first item) (second item)) (third item))
	;(push (list (list (first item) (second item))
	;	    (third item)) *scores*))
	)
  )

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

; Calculate the score for a given list.
(defun score-list (l)
  (setf ret 0)
  ;(print l)
  (loop for i1 in l
	do
	(loop for i2 in (cdr (member i1 l))
	      ;initially
	      ;(print (cdr (member i1 l)))
	      do
	      (setf ret (+ ret (aref *items* i1 i2)))))
  ret
  )

; Calculate the score while generating the permutation lists.
(defun permutate (l &optional a)
  (if (null l)
    (setf *score* (max *score* (score-list (reverse a))))
    ;(print (reverse a))
    (dolist (i l)
      (permutate (remove i l) (cons i a))))
  )

(defun n90 ()
  (input)
  (permutate (loop for x from 0 to (1- (car *n-m*))
		   collect x))
  (princ *score*)
  )

(n90)
0