結果

問題 No.7 プライムナンバーゲーム
ユーザー mikan-watermikan-water
提出日時 2024-01-21 16:44:14
言語 Common Lisp
(sbcl 2.3.8)
結果
AC  
実行時間 863 ms / 5,000 ms
コード長 1,460 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 37,668 KB
実行使用メモリ 29,728 KB
最終ジャッジ日時 2024-01-21 16:44:21
合計ジャッジ時間 6,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
29,344 KB
testcase_01 AC 10 ms
29,344 KB
testcase_02 AC 863 ms
29,728 KB
testcase_03 AC 61 ms
29,600 KB
testcase_04 AC 24 ms
29,472 KB
testcase_05 AC 22 ms
29,472 KB
testcase_06 AC 247 ms
29,600 KB
testcase_07 AC 170 ms
29,600 KB
testcase_08 AC 79 ms
29,600 KB
testcase_09 AC 373 ms
29,600 KB
testcase_10 AC 10 ms
29,344 KB
testcase_11 AC 173 ms
29,600 KB
testcase_12 AC 597 ms
29,600 KB
testcase_13 AC 660 ms
29,600 KB
testcase_14 AC 833 ms
29,728 KB
testcase_15 AC 819 ms
29,728 KB
testcase_16 AC 754 ms
29,728 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 21 JAN 2024 07:44:14 AM):

; file: /home/judge/data/code/Main.lisp
; in: DEFUN N7
;     (SETF *WIN-LOSE* (MAKE-ARRAY (1+ *N*) :INITIAL-ELEMENT NIL))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::*WIN-LOSE*

; in: DEFUN UPDATE-WIN-LOSE
;     (SETF (AREF *WIN-LOSE* N) T)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::*WIN-LOSE*

;     (AREF *WIN-LOSE* Y)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::*WIN-LOSE*

; 
; caught WARNING:
;   1 more use of undefined variable *WIN-LOSE*


; file: /home/judge/data/code/Main.lisp
; in: DEFUN CREATE-PRIMES
;     (SETF (AREF NUMS 1) NIL)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::NUMS

;     (SETF (AREF NUMS 0) NIL)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::NUMS

;     (SETF NUMS (MAKE-ARRAY (1+ N) :INITIAL-ELEMENT T))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::NUMS

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


; file: /home/judge/data/code/Main.lisp
; in: DEFUN UPDATE-WIN-LOSE
;     (AREF *WIN-LOSE* Y)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::Y

;     (<= Y 1)
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::Y

;     (SETF Y (- N I))
; 
; caught WARNING:
;   undefined variable: COMMON-LISP-USER::Y
; 
; compilation unit finished
;   Undefined variables:
;     *WIN-LOSE* NUMS Y
;   caught 11 WARNING conditions

; wrote /home/judge/data/code/Main.fasl
; compilation finished in 0:00:00.038

ソースコード

diff #

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ONLY implement algolythm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; variables
(defparameter *n* 12)
(defparameter *primes* '())

; functions

; create a list of prime numbers below n.
(defun create-primes (n)
  ; create nil array, n elements
  (setf nums (make-array (1+ n)
	      :initial-element t))
  ; 0th, 1st is nil
  (setf (aref nums 0) nil)
  (setf (aref nums 1) nil)

  ; Eratosthenes
  (loop for i from 2 to n
	while (<= i (sqrt n))
	do
	(if (equal (aref nums i) t)
	  (loop for j from 2 to n
		while (<= (* i j) n)
		do
		(setf (aref nums (* i j)) nil)
		)
	  )
	)
  ; push the index of t
  (loop for flag across nums
	for i from 0 to n
	do
	(if (equal flag t)
	  (push i *primes*)))
  (setf *primes* (reverse *primes*))
  )

(defun calc-win-lose (n)
  (loop for i from 2 to n
	do
	(update-win-lose i))
  )

(defun update-win-lose (n)
  (loop for i in *primes*
	with x = (- n 2)
	do
	(setf y (- n i))
	(cond
	  ((or (<= y 1) (< x 0))
	   nil)
	  ((equal (aref *win-lose* y) nil)
	   ; you win when you get this number 
	   (setf (aref *win-lose* n) t))
	  ; you lose
	  (t nil)))
  )

(defun input ()
  (setf *n* (parse-integer (read-line)))
  )

(defun n7 ()
  (input)
  ; win-lose array
  ; win:t lose:nil
  (setf *win-lose* (make-array (1+ *n*)
			     :initial-element nil))
  (create-primes *n*)
  (calc-win-lose *n*)
  (if (aref *win-lose* *n*)
    (princ "Win")
    (princ "Lose"))

 )

(n7)
0