結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | mikan-water |
提出日時 | 2024-01-21 16:44:14 |
言語 | Common Lisp (sbcl 2.3.8) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
21,760 KB |
testcase_01 | AC | 11 ms
21,760 KB |
testcase_02 | AC | 895 ms
22,144 KB |
testcase_03 | AC | 63 ms
21,888 KB |
testcase_04 | AC | 24 ms
21,888 KB |
testcase_05 | AC | 24 ms
22,016 KB |
testcase_06 | AC | 262 ms
22,016 KB |
testcase_07 | AC | 181 ms
22,016 KB |
testcase_08 | AC | 84 ms
21,888 KB |
testcase_09 | AC | 393 ms
22,016 KB |
testcase_10 | AC | 11 ms
21,760 KB |
testcase_11 | AC | 180 ms
22,016 KB |
testcase_12 | AC | 633 ms
22,016 KB |
testcase_13 | AC | 671 ms
22,016 KB |
testcase_14 | AC | 883 ms
22,016 KB |
testcase_15 | AC | 836 ms
22,016 KB |
testcase_16 | AC | 769 ms
22,016 KB |
コンパイルメッセージ
; 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)