結果
問題 | No.660 家を通り過ぎないランダムウォーク問題 |
ユーザー | Common Lisp |
提出日時 | 2024-11-15 15:50:15 |
言語 | Common Lisp (sbcl 2.3.8) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 1,853 bytes |
コンパイル時間 | 390 ms |
コンパイル使用メモリ | 37,520 KB |
実行使用メモリ | 46,208 KB |
最終ジャッジ日時 | 2024-11-15 15:50:20 |
合計ジャッジ時間 | 4,614 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
43,060 KB |
testcase_01 | AC | 62 ms
41,536 KB |
testcase_02 | AC | 62 ms
34,048 KB |
testcase_03 | AC | 59 ms
33,792 KB |
testcase_04 | AC | 59 ms
34,048 KB |
testcase_05 | AC | 59 ms
33,792 KB |
testcase_06 | AC | 58 ms
33,920 KB |
testcase_07 | AC | 63 ms
33,920 KB |
testcase_08 | AC | 59 ms
33,920 KB |
testcase_09 | AC | 63 ms
33,920 KB |
testcase_10 | AC | 65 ms
34,048 KB |
testcase_11 | AC | 58 ms
33,792 KB |
testcase_12 | AC | 60 ms
33,792 KB |
testcase_13 | AC | 60 ms
33,920 KB |
testcase_14 | AC | 59 ms
34,048 KB |
testcase_15 | AC | 60 ms
33,792 KB |
testcase_16 | AC | 60 ms
33,920 KB |
testcase_17 | AC | 58 ms
34,048 KB |
testcase_18 | AC | 58 ms
33,920 KB |
testcase_19 | AC | 58 ms
33,792 KB |
testcase_20 | AC | 63 ms
34,048 KB |
testcase_21 | AC | 63 ms
33,920 KB |
testcase_22 | AC | 60 ms
33,792 KB |
testcase_23 | AC | 59 ms
33,792 KB |
testcase_24 | AC | 60 ms
33,920 KB |
testcase_25 | AC | 61 ms
33,792 KB |
testcase_26 | AC | 65 ms
33,792 KB |
testcase_27 | AC | 59 ms
33,792 KB |
testcase_28 | AC | 66 ms
33,664 KB |
testcase_29 | AC | 59 ms
34,048 KB |
testcase_30 | AC | 62 ms
33,920 KB |
testcase_31 | AC | 62 ms
33,920 KB |
testcase_32 | AC | 60 ms
34,176 KB |
testcase_33 | AC | 61 ms
34,304 KB |
testcase_34 | AC | 59 ms
34,304 KB |
testcase_35 | AC | 64 ms
35,712 KB |
testcase_36 | AC | 65 ms
35,840 KB |
testcase_37 | AC | 64 ms
35,840 KB |
testcase_38 | AC | 73 ms
39,168 KB |
testcase_39 | AC | 73 ms
39,296 KB |
testcase_40 | AC | 73 ms
39,424 KB |
testcase_41 | AC | 91 ms
43,264 KB |
testcase_42 | AC | 85 ms
43,264 KB |
testcase_43 | AC | 87 ms
44,928 KB |
testcase_44 | AC | 89 ms
46,208 KB |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 15 NOV 2024 03:50:15 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.089
ソースコード
(defconstant +mod+ 1000000007) (defun %mod-inverse (a_ m_) (let ((a a_) (m m_) (b m_) (u 1) (v 0)) (loop while (plusp b) do (let ((s (floor a b))) (decf a (* s b)) (rotatef a b) (decf u (* s v)) (rotatef u v))) (mod u m))) (defvar *mod-fact* (make-array 1000001 :element-type 'integer)) (defvar *mod-fact-inv* (make-array 1000001 :element-type 'integer)) (defvar *mod-inv* (make-array 1000001 :element-type 'integer)) (defun %init-mod-combination (n m) (setf (aref *mod-fact* 0) 1 (aref *mod-fact-inv* n) 1 (aref *mod-inv* 0) 1) (loop for i from 1 to n do (setf (aref *mod-fact* i) (mod (* i (aref *mod-fact* (1- i))) m))) (setf (aref *mod-fact-inv* n) (%mod-inverse (aref *mod-fact* n) m)) (loop for i from (1- n) downto 0 do (setf (aref *mod-fact-inv* i) (mod (* (aref *mod-fact-inv* (1+ i)) (1+ i)) m))) (loop for i from 1 to n do (setf (aref *mod-inv* i) (mod (* (aref *mod-fact* (1- i)) (aref *mod-fact-inv* i)) m)))) (defun %mod-nCk (n k m) (if (or (minusp k) (< n k)) 0 (mod (* (aref *mod-fact* n) (aref *mod-fact-inv* k) (aref *mod-fact-inv* (- n k))) m))) (defun %mod-nPk (n k m) (if (or (minusp k) (< n k)) 0 (mod (* (aref *mod-fact* n) (aref *mod-fact-inv* (- n k))) m))) (defun %mod-nHk (n k m) (if (= n k 0) 1 (%mod-nCk (+ n k -1) k m))) (defun main (&rest argv) (declare (ignorable argv)) (%init-mod-combination 500001 +mod+) (let* ((n (read)) (res 0) (k 0)) (loop for i from (1- n) below (* 2 n) by 2 do (let ((x (%mod-nCk i (+ n k -1) +mod+)) (y (%mod-nCk i (+ n k) +mod+))) (incf k) (setq res (mod (+ res x (- y)) +mod+)))) (format t "~d~%" res))) (main)