結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-10-08 12:43:12 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 824 bytes |
| コンパイル時間 | 1,217 ms |
| コンパイル使用メモリ | 38,512 KB |
| 実行使用メモリ | 31,896 KB |
| 最終ジャッジ日時 | 2024-10-08 12:43:16 |
| 合計ジャッジ時間 | 1,755 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 21 WA * 9 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 08 OCT 2024 12:43:12 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.050
ソースコード
; 与えられた Ci を昇順ソートして小さいものから足し続ける
; m を超えたときのインデックスを出力する
; 【解1】for ループ
; (defun main ()
; (let* ((n (read))
; (m (read))
; (xs (sort (loop repeat n collect (read)) #'<)))
; (loop for i below n
; for 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)
Common Lisp