結果

問題 No.90 品物の並び替え
ユーザー mikan-watermikan-water
提出日時 2024-01-25 09:47:43
言語 Common Lisp
(sbcl 2.3.8)
結果
RE  
実行時間 -
コード長 1,597 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 37,784 KB
実行使用メモリ 35,988 KB
最終ジャッジ日時 2024-09-28 07:15:37
合計ジャッジ時間 1,510 ms
ジャッジサーバーID
(参考情報)
judge2 / 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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 28 SEP 2024 07:15:34 AM):

; file: /home/judge/data/code/Main.lisp
; in: DEFUN N90
;     (LOOP FOR X
;           REPEAT (CAR *N-M*)
;           COLLECT X)
; 
; caught ERROR:
;   during macroexpansion of (LOOP FOR X ...). Use *BREAK-ON-SIGNALS* to intercept.
;   
;    REPEAT is an unknown keyword in FOR or AS clause in LOOP.
;   current LOOP context: FOR X REPEAT (CAR *N-M*) COLLECT.

;     (PERMUTATE
;      (LOOP FOR X
;            REPEAT (CAR *N-M*)
;            COLLECT X))
; 
; note: deleting unreachable code

; 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

; 
; 

ソースコード

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 repeat (car *n-m*)
		   collect x))
  (princ *score*)
  )

(n90)
0