結果
問題 | No.573 a^2[i] = a[i] |
ユーザー | Common Lisp |
提出日時 | 2024-11-16 19:21:44 |
言語 | Common Lisp (sbcl 2.3.8) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 2,040 bytes |
コンパイル時間 | 1,709 ms |
コンパイル使用メモリ | 39,428 KB |
実行使用メモリ | 52,096 KB |
最終ジャッジ日時 | 2024-11-16 19:21:54 |
合計ジャッジ時間 | 10,009 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
45,824 KB |
testcase_01 | AC | 137 ms
45,696 KB |
testcase_02 | AC | 135 ms
45,696 KB |
testcase_03 | AC | 151 ms
45,696 KB |
testcase_04 | AC | 161 ms
45,696 KB |
testcase_05 | AC | 139 ms
45,696 KB |
testcase_06 | AC | 133 ms
45,696 KB |
testcase_07 | AC | 135 ms
45,696 KB |
testcase_08 | AC | 134 ms
45,696 KB |
testcase_09 | AC | 133 ms
45,824 KB |
testcase_10 | AC | 136 ms
45,824 KB |
testcase_11 | AC | 133 ms
45,696 KB |
testcase_12 | AC | 138 ms
45,696 KB |
testcase_13 | AC | 138 ms
45,824 KB |
testcase_14 | AC | 139 ms
45,824 KB |
testcase_15 | AC | 139 ms
45,696 KB |
testcase_16 | AC | 137 ms
45,696 KB |
testcase_17 | AC | 135 ms
45,696 KB |
testcase_18 | AC | 136 ms
45,824 KB |
testcase_19 | AC | 137 ms
45,824 KB |
testcase_20 | AC | 136 ms
45,696 KB |
testcase_21 | AC | 137 ms
45,696 KB |
testcase_22 | AC | 137 ms
45,696 KB |
testcase_23 | AC | 136 ms
45,824 KB |
testcase_24 | AC | 137 ms
45,568 KB |
testcase_25 | AC | 137 ms
45,824 KB |
testcase_26 | AC | 137 ms
45,824 KB |
testcase_27 | AC | 135 ms
45,824 KB |
testcase_28 | AC | 137 ms
45,824 KB |
testcase_29 | AC | 137 ms
45,696 KB |
testcase_30 | AC | 135 ms
45,696 KB |
testcase_31 | AC | 136 ms
45,696 KB |
testcase_32 | AC | 139 ms
45,696 KB |
testcase_33 | AC | 138 ms
45,696 KB |
testcase_34 | AC | 135 ms
45,824 KB |
testcase_35 | AC | 137 ms
45,824 KB |
testcase_36 | AC | 137 ms
45,824 KB |
testcase_37 | AC | 136 ms
45,696 KB |
testcase_38 | AC | 138 ms
45,824 KB |
testcase_39 | AC | 139 ms
45,824 KB |
testcase_40 | AC | 138 ms
45,824 KB |
testcase_41 | AC | 135 ms
45,824 KB |
testcase_42 | AC | 137 ms
46,080 KB |
testcase_43 | AC | 137 ms
46,080 KB |
testcase_44 | AC | 140 ms
46,208 KB |
testcase_45 | AC | 142 ms
46,336 KB |
testcase_46 | AC | 222 ms
52,096 KB |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 16 NOV 2024 07:21:44 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.091
ソースコード
(defconstant +mod+ 1000000007) (defun %mod-pow (a_ n_ m_) (let ((a a_) (n n_) (m m_) (res 1)) (loop while (plusp n) do (unless (zerop (logand n 1)) (setq res (mod (* res a) m))) (setq a (mod (* a a) m)) (setq n (ash n -1))) res)) (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 3000001 :element-type 'integer)) (defvar *mod-fact-inv* (make-array 3000001 :element-type 'integer)) (defvar *mod-inv* (make-array 3000001 :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)) (let* ((n (read)) (res 0)) (%init-mod-combination 1000000 +mod+) (loop for i from 1 to n do (let ((a (mod (* (%mod-nCk n i +mod+) (%mod-pow i (- n i) +mod+)) +mod+))) (setq res (mod (+ res a) +mod+)))) (format t "~d~%" res))) (main)