結果

問題 No.458 異なる素数の和
ユーザー Common Lisp
提出日時 2024-11-14 01:38:06
言語 Common Lisp
(sbcl 2.5.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 37,412 KB
実行使用メモリ 30,376 KB
最終ジャッジ日時 2024-11-14 01:38:18
合計ジャッジ時間 6,133 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 14 NOV 2024 01:38:11 AM):

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

ソースコード

diff #

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((n (read))
         (dp (make-array 20001 :element-type 'integer :initial-element -123))
         (sieve (make-array 20001 :initial-element nil)))
    (setf (aref dp 0) 0)
    (loop for i from 2 to 20000 do
          (loop for j from (* i i) to 20000 by i do
                (setf (aref sieve j) t))
          (unless (aref sieve i)
                  (loop for j from (- 20000 i) downto 0 do
                        (setf (aref dp (+ i j)) (max (1+ (aref dp j)) (aref dp (+ i j)))))))
    (format t "~d~%" (max -1 (aref dp n)))))

(main)
0