結果
| 問題 |
No.792 真理関数をつくろう
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-12 12:07:43 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 2,332 bytes |
| コンパイル時間 | 311 ms |
| コンパイル使用メモリ | 36,040 KB |
| 実行使用メモリ | 33,400 KB |
| 最終ジャッジ日時 | 2024-12-31 14:48:55 |
| 合計ジャッジ時間 | 1,712 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 31 DEC 2024 02:48:52 PM): ; file: /home/judge/data/code/Main.lisp ; in: DEFUN SOLVE-LINE ; (DEFUN SOLVE-LINE (N S) ; (IF (CHAR= (CHAR S (- # 1)) #\0) ; NIL ; (SPLIT-TO-FUN-CHARS-BY-SPACE (SUBSEQ S 0 (- # 1)) 0 ; #'CHAR-BOOL-TO-P-STR))) ; --> SB-IMPL::%DEFUN SB-IMPL::%DEFUN SB-INT:NAMED-LAMBDA ; ==> ; #'(SB-INT:NAMED-LAMBDA SOLVE-LINE ; (N S) ; (DECLARE (SB-C::TOP-LEVEL-FORM)) ; (BLOCK SOLVE-LINE ; (IF (CHAR= (CHAR S #) #\0) ; NIL ; (SPLIT-TO-FUN-CHARS-BY-SPACE (SUBSEQ S 0 #) 0 ; #'CHAR-BOOL-TO-P-STR)))) ; ; 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.023
ソースコード
(defun split (string &key (delimiterp #'delimiterp))
(loop :for beg = (position-if-not delimiterp string)
:then (position-if-not delimiterp string :start (1+ end))
:for end = (and beg (position-if delimiterp string :start beg))
:when beg :collect (subseq string beg end)
:while end))
(defun delimiterp (c) (or (char= c #\Space) (char= c #\,)))
(defun split-to-chars-by-space (str num &optional (result ()))
(if (< num (length str))
(if (char= (char str num) #\Space)
(split-to-chars-by-space str (+ 1 num) result)
(split-to-chars-by-space str (+ 1 num) (cons (char str num) result)))
result))
; (split-to-fun-chars-by-space "1 0 1 1 0" 0 #'char-bool-to-p-str)
; -> ("¬P_5" "P_4" "P_3" "¬P_2" "P_1")
(defun split-to-fun-chars-by-space (str num f &optional (result ()))
(if (< num (length str))
(if (char= (char str num) #\Space)
(split-to-fun-chars-by-space str (+ 1 num) f result)
(split-to-fun-chars-by-space str (+ 1 num) f (cons (funcall f (+ 1 (length result)) (char str num)) result)))
result))
; (char-bool-to-p-str 1 #\0) -> ¬P_1
; (char-bool-to-p-str 2 #\1) -> P_2
(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 (n s)
(if (char= (char s (- (length s) 1)) #\0)
nil
(split-to-fun-chars-by-space (subseq s 0 (- (length s) 1)) 0 #'char-bool-to-p-str)))
(defun solve-lines (n limit &optional (result ()))
(if (= 0 limit) result
(let ((solved (solve-line n (read-line))))
(solve-lines n (- limit 1) (if solved (cons solved result) result)))))
(defun output-lines (lines &optional (output-count 0))
(if (= (length lines) 0) nil
(if (car lines) (progn (if (> output-count 0) (format t "∨"))
(format t "(~{~A~^∧~})" (reverse (car lines)))
(output-lines (cdr lines) (+ output-count 1)))
(output-lines (cdr lines) output-count))))
(let* ((n (parse-integer (read-line)))
(m (solve-lines n (expt 2 n))))
(format t "A=")
(if (not m)
(format t "⊥")
(if (= (length m) (expt 2 n))
(format t "⊤")
(output-lines (reverse m))))
(format t "~%"))