結果

問題 No.7 プライムナンバーゲーム
コンテスト
ユーザー Common Lisp
提出日時 2024-10-23 11:43:48
言語 Common Lisp
(sbcl 2.6.9)
コンパイル:
sbclc _filename_
実行:
sbcl --script Main.fasl
結果
AC  
実行時間 17 ms / 5,000 ms
+ 317µs
コード長 1,224 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 890 ms
コンパイル使用メモリ 38,644 KB
実行使用メモリ 28,188 KB
最終ジャッジ日時 2026-10-11 11:00:18
合計ジャッジ時間 1,486 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 11 OCT 2026 11:00:15 AM):

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

ソースコード

diff #
raw source code

(defun prime (x)
  (let ((primes (make-array (1+ x) :initial-contents
                  (loop for i from 0 to x
                        collect (if (evenp i) 2 i)))))
    (setf (aref primes 0) 1)
    (loop for i from 3 to (+ 2 (isqrt x)) by 2
          do (when (= (aref primes i) i)
                   (loop for j from (* 2 i) to x by i
                         do (when (= (aref primes j) j)
                                  (setf (aref primes j) i)))))
    (loop for i from 2 to x
          when (= (aref primes i) i)
          collect i)))

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((n (read))
         (primes (prime (1+ n)))
         (dp (make-array (1+ n) :initial-element 0)))
    (setf (aref dp 0) 1)
    (setf (aref dp 1) 1)
    (loop for i from 2 to n
          do (block inner
               (loop for p in primes
                     do (when (> p i)
                              (return-from inner))
                        (when (zerop (aref dp (- i p)))
                              (setf (aref dp i) 1)
                              (return-from inner)))))
    (format t "~A~%" (if (zerop (aref dp n))
                         "Lose"
                         "Win"))))

#-swank(main)
0