結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-21 16:44:14 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 895 ms / 5,000 ms |
| コード長 | 1,460 bytes |
| コンパイル時間 | 248 ms |
| コンパイル使用メモリ | 35,760 KB |
| 実行使用メモリ | 22,144 KB |
| 最終ジャッジ日時 | 2024-09-28 06:15:06 |
| 合計ジャッジ時間 | 6,864 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 28 SEP 2024 06:14:59 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.018
ソースコード
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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)