結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | mikan-water |
提出日時 | 2024-01-21 16:42:50 |
言語 | Common Lisp (sbcl 2.3.8) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,458 bytes |
コンパイル時間 | 109 ms |
コンパイル使用メモリ | 37,776 KB |
実行使用メモリ | 32,664 KB |
最終ジャッジ日時 | 2024-09-28 06:14:59 |
合計ジャッジ時間 | 6,861 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 28 SEP 2024 06:14:52 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.034
ソースコード
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 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)