結果
| 問題 |
No.2561 みんな大好きmod 998
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-11-05 22:33:26 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,128 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 37,772 KB |
| 実行使用メモリ | 35,992 KB |
| 最終ジャッジ日時 | 2024-11-05 22:33:29 |
| 合計ジャッジ時間 | 2,476 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 44 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 05 NOV 2024 10:33:26 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.016
ソースコード
(defun vector-append (vec1 vec2)
(let ((len1 (length vec1))
(len2 (length vec2)))
(let ((result (make-array (+ len1 len2) :element-type (array-element-type vec1))))
(dotimes (i len1)
(setf (aref result i) (aref vec1 i)))
(dotimes (i len2)
(setf (aref result (+ i len1)) (aref vec2 i)))
result)))
(defun combinations (vec k)
(if (= k 0)
(vector)
(when (not (zerop (length vec)))
(let ((first (aref vec 0))
(rest (subseq vec 1)))
(let ((with-first (mapcar (lambda (x) (vector first x))
(combinations rest (1- k)))))
(vector-append with-first (combinations rest k)))))))
(defun main (&rest argv)
(declare (ignorable argv))
(let* ((n (read))
(k (read))
(a (make-array n))
(res 0)
(m1 998)
(m2 998244353))
(dotimes (i n) (setf (aref a i) (read)))
(loop for i across (combinations a k)
with s = (reduce #'+ i)
when (>= (mod s m1) (mod s m2))
do (incf res))
(format t "~d~%" (mod res m1))))
(main)
Common Lisp