結果
| 問題 |
No.792 真理関数をつくろう
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-12 14:37:50 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 1,423 bytes |
| コンパイル時間 | 1,170 ms |
| コンパイル使用メモリ | 38,056 KB |
| 実行使用メモリ | 34,944 KB |
| 最終ジャッジ日時 | 2025-01-01 23:42:05 |
| 合計ジャッジ時間 | 2,560 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 01 JAN 2025 11:42:01 PM): ; file: /home/judge/data/code/Main.lisp ; in: DEFUN SOLVE-LINES ; (DEFUN SOLVE-LINES (N LIMIT) ; (LET ((RESULT (MAKE-ARRAY LIMIT :INITIAL-ELEMENT NIL))) ; (DOTIMES (IDX LIMIT) (SETF # #)) ; RESULT)) ; --> SB-IMPL::%DEFUN SB-IMPL::%DEFUN SB-INT:NAMED-LAMBDA ; ==> ; #'(SB-INT:NAMED-LAMBDA SOLVE-LINES ; (N LIMIT) ; (DECLARE (SB-C::TOP-LEVEL-FORM)) ; (BLOCK SOLVE-LINES ; (LET ((RESULT #)) ; (DOTIMES (IDX LIMIT) (SETF #)) ; RESULT))) ; ; caught STYLE-WARNING: ; The variable N is defined but never used. ; ; compilation unit finished ; caught 1 STYLE-WARNING condition ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.060
ソースコード
(defun split-to-apply-fun-by-space (str num f &optional (result ()))
(if (< num (length str))
(if (char= (char str num) #\Space)
(split-to-apply-fun-by-space str (+ 1 num) f result)
(split-to-apply-fun-by-space str (+ 1 num) f (cons (funcall f (+ 1 (length result)) (char str num)) result)))
(reverse result)))
(defun char-bool-to-p-str (num c)
(if (char= #\0 c) (format nil "¬P_~A" num) (format nil "P_~A" num)))
(defun solve-line (s)
(if (char= #\0 (aref s (- (length s) 1)))
nil
(split-to-apply-fun-by-space (subseq s 0 (- (length s) 1)) 0 #'char-bool-to-p-str)))
(defun join-by-AND (ss)
(if (null ss) ss
(format nil "(~{~A~^∧~})" ss)))
(defun solve-lines (n limit)
(let ((result (make-array limit :initial-element nil)))
(dotimes (idx limit)
(setf (aref result idx) (join-by-AND (solve-line (read-line)))))
result))
(defun output-lines (ss)
(loop for i from 0
until (>= i (length ss))
do (if (> i 0) (format t "∨"))
(format t (aref ss i))))
(let* ((n (parse-integer (read-line)))
(m (solve-lines n (expt 2 n)))
(m2 (remove-if (lambda (x) (null x)) m)))
(format t "A=")
(if (= 0 (length m2))
(format t "⊥")
(if (= (length m2) (expt 2 n))
(format t "⊤")
(output-lines m2)))
(format t "~%"))