結果

問題 No.792 真理関数をつくろう
ユーザー iwotiwot
提出日時 2020-09-12 11:47:40
言語 Common Lisp
(sbcl 2.3.8)
結果
WA  
実行時間 -
コード長 2,112 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 34,756 KB
実行使用メモリ 31,464 KB
最終ジャッジ日時 2023-08-30 04:50:36
合計ジャッジ時間 2,794 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
23,752 KB
testcase_01 WA -
testcase_02 AC 11 ms
27,816 KB
testcase_03 WA -
testcase_04 AC 9 ms
22,852 KB
testcase_05 WA -
testcase_06 AC 41 ms
26,624 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 10 ms
27,772 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 24 ms
29,728 KB
testcase_17 WA -
testcase_18 AC 10 ms
23,732 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 55 ms
31,464 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 30 AUG 2023 04:50:33 AM):
; processing (DEFUN SPLIT ...)
; processing (DEFUN DELIMITERP ...)
; processing (DEFUN SPLIT-TO-CHARS-BY-SPACE ...)
; processing (DEFUN SPLIT-TO-FUN-CHARS-BY-SPACE ...)
; processing (DEFUN CHAR-BOOL-TO-P-STR ...)
; processing (DEFUN SOLVE-LINE ...)
; 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)))
; --> PROGN 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.

; processing (DEFUN SOLVE-LINES ...)
; processing (DEFUN OUTPUT-LINES ...)
; processing (LET* (# #) ...); 
; compilation unit finished
;   caught 1 STYLE-WARNING condition


; wrote /home/judge/data/code/Main.fasl
; compilation finished in 0:00:00.122

ソースコード

diff #

(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 (input ()))
    (if (= 0 limit) input
        (solve-lines n (- limit 1) (cons (solve-line n (read-line)) input))))

(defun output-lines (lines &optional (sep nil))
    (if (= (length lines) 0) nil
        (if (car lines) (progn (if sep (format t "~A" sep))
                               (format t "(~{~A~^∧~})" (reverse (car lines)))
                               (output-lines (cdr lines) "∨"))
            (output-lines (cdr lines) "∨"))))

(let* ((n (parse-integer (read-line)))
       (m (solve-lines n (expt 2 n))))
    (format t "A=")
    (output-lines (reverse m))
    (format t "~%"))
0