結果

問題 No.1512 作文
ユーザー motoshira
提出日時 2021-05-21 22:28:32
言語 Common Lisp
(sbcl 2.5.0)
結果
WA  
実行時間 -
コード長 1,568 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 39,940 KB
実行使用メモリ 72,024 KB
最終ジャッジ日時 2024-10-10 09:16:57
合計ジャッジ時間 2,853 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 26 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 10 OCT 2024 09:16:54 AM):

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

ソースコード

diff #

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 obj
      (princ obj stream)
      (terpri stream))))

(defun ok (xs)
  (sb-int:named-let rec ((xs xs)
                         (c #\a))
    (or (null xs)
        (and (char<= c (first xs))
             (rec (rest xs)
                  (first xs))))))

(defun get-l-and-r (xs)
  (when (ok xs)
    (list (length xs)
          (first (sort (copy-seq xs) #'char<))
          (first (sort (copy-seq xs) #'char>)))))

(define-modify-macro maxf (var) max)

(defun char->int (c)
  (- (char-code c)
     (char-code #\a)))

(defun main ()
  (let* ((n (read))
         (ss (sort (remove-if #'null (mapcar #'get-l-and-r (loop repeat n collect (concatenate 'list (read-line))))) #'(lambda (xs ys)
                                                                                                                         (if (char= (second xs) (second ys))
                                                                                                                             (char< (third xs) (third ys))
                                                                                                                             (char< (second xs) (second ys)))))))
    (let ((dp (make-array 26 :initial-element 0)))
      (loop for (cnt l r) in ss
            do (maxf (aref dp (char->int r))
                     (+ (aref dp (char->int l))
                        cnt)))
      (println (reduce #'max dp)))))

#-swank (main)
0