結果

問題 No.50 おもちゃ箱
ユーザー Common Lisp
提出日時 2024-11-12 23:17:57
言語 Common Lisp
(sbcl 2.5.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,116 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 39,560 KB
実行使用メモリ 30,140 KB
最終ジャッジ日時 2024-11-12 23:18:00
合計ジャッジ時間 2,343 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 12 NOV 2024 11:17:57 PM):

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

ソースコード

diff #

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((*read-default-float-format* 'double-float)
         (dp1 (make-array (ash 1 10) :initial-element nil))
         (dp2 (make-array (ash 1 10) :initial-element nil))
         (n (read))
         (a (make-array n :element-type 'integer)))
    (dotimes (i n) (setf (aref a i) (read)))
    (let* ((m (read))
           (b (make-array m :element-type 'integer)))
      (dotimes (i m) (setf (aref b i) (read)))
      (sort b #'>)
      (setf (aref dp1 0) t)
      (dotimes (i m)
        (dotimes (j (ash 1 n))
          (let ((c 0))
            (dotimes (k n)
              (unless (evenp (ash j (- k)))
                      (incf c (aref a k))))
            (unless (> c (aref b i))
                    (loop for k from (1- (ash 1 n)) downto 0 do (setf (aref dp2 (logior j k)) (or (aref dp2 (logior j k)) (aref dp1 k)))))))
        (loop for k from (1- (ash 1 n)) downto 0 do (setf (aref dp1 k) (aref dp2 k)))
        (when (aref dp1 (1- (ash 1 n)))
              (format t "~d~%" (1+ i))
              (return-from main)))
      (format t "-1~%"))))

(main)
0