結果
問題 | No.156 キャンディー・ボックス |
ユーザー |
![]() |
提出日時 | 2024-10-08 12:44:15 |
言語 | Common Lisp (sbcl 2.5.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 826 bytes |
コンパイル時間 | 390 ms |
コンパイル使用メモリ | 35,108 KB |
実行使用メモリ | 21,888 KB |
最終ジャッジ日時 | 2024-10-08 12:44:18 |
合計ジャッジ時間 | 2,254 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 08 OCT 2024 12:44:15 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.021
ソースコード
; 与えられた Ci を昇順ソートして小さいものから足し続ける; m を超えたときのインデックスを出力する; 【解1】for ループ(defun main ()(let* ((n (read))(m (read))(xs (sort (loop repeat n collect (read)) #'<)))(loop for i below nfor s = (car xs) then (+ s (nth i xs))until (> s m)finally (princ i))(terpri)))(main); 【解2】再帰; (defun scanl (fn init xs); (if (null xs); (list init); (cons init (scanl fn (funcall fn (car xs) init) (cdr xs))))); (defun main (); (let* ((n (read)); (m (read)); (xs (sort (loop repeat n collect (read)) #'<))); (princ (length (remove-if #'plusp (map 'list (lambda (x) (- x m)) (scanl #'+ (car xs) xs))))); (terpri))); (main)