結果
| 問題 |
No.42 貯金箱の溜息
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-11-08 21:26:02 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 263 ms / 5,000 ms |
| コード長 | 1,096 bytes |
| コンパイル時間 | 1,282 ms |
| コンパイル使用メモリ | 29,184 KB |
| 実行使用メモリ | 44,800 KB |
| 最終ジャッジ日時 | 2024-11-08 21:26:06 |
| 合計ジャッジ時間 | 1,691 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 08 NOV 2024 09:26:03 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.049
ソースコード
(defconstant +mod+ 1000000009)
(defconstant +max+ 1000000)
(defun %mod-inverse (x)
(if (= x 1)
1
(mod (* (- +mod+ (floor +mod+ x)) (%mod-inverse (mod +mod+ x))) +mod+)))
(defun main (&rest argv)
(declare (ignorable argv))
(let* ((query (read))
(dp (make-array +max+ :initial-element 1 :element-type 'integer))
(coins (list 5 10 50 100 500)))
(dolist (coin coins)
(loop for i from coin below +max+ do
(setf (aref dp i) (mod (+ (aref dp i) (aref dp (- i coin))) +mod+))))
(dotimes (_ query)
(let* ((p (read))
(q (floor p 500))
(r (mod p 500))
(res 0))
(dotimes (i 6)
(let ((s 1))
(dotimes (j 6)
(when (/= i j)
(setq s (mod (* s (- (+ q +mod+) j)) +mod+))))
(dotimes (j 6)
(when (/= i j)
(setq s (mod (* s (%mod-inverse (mod (- (+ i +mod+) j) +mod+))) +mod+))))
(setq res (mod (+ res (* s (aref dp (+ (* 500 i) r)))) +mod+))))
(format t "~d~%" res)))))
(main)
Common Lisp