結果

問題 No.291 黒い文字列
コンテスト
ユーザー Common Lisp
提出日時 2024-11-11 16:41:49
言語 Common Lisp
(sbcl 2.6.3)
コンパイル:
sbclc _filename_
実行:
sbcl --script Main.fasl
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,752 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 439 ms
コンパイル使用メモリ 94,364 KB
実行使用メモリ 25,472 KB
最終ジャッジ日時 2026-05-09 13:13:59
合計ジャッジ時間 1,900 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 09 MAY 2026 01:13:56 PM):

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

ソースコード

diff #
raw source code

(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((s (read-line))
         (dp (make-array (list 2 21 21 21 21) :element-type 'integer :initial-element -1))
         (a 0)
         (b 1)
         (res 0))
    (setf (aref dp 0 0 0 0 0) 0)
    (loop for c across s do
          (dotimes (k 21)
            (dotimes (u (1+ k))
              (dotimes (r (1+ u))
                (dotimes (o (1+ r))
                  (let ((now (aref dp a k u r o)))
                    (unless (= now -1)
                            (setf (aref dp b k u r o) (max (aref dp b k u r o) now))
                            (when (and (or (char= c #\K) (char= c #\?)) (<= (1+ k) 20))
                                  (setf (aref dp b (1+ k) u r o) (max (aref dp b (1+ k) u r o) now)))
                            (when (and (or (char= c #\U) (char= c #\?)) (<= (1+ u) k))
                                  (setf (aref dp b k (1+ u) r o) (max (aref dp b k (1+ u) r o) now)))
                            (when (and (or (char= c #\R) (char= c #\?)) (<= (1+ r) k))
                                  (setf (aref dp b k u (1+ r) o) (max (aref dp b k u (1+ r) o) now)))
                            (when (and (or (char= c #\O) (char= c #\?)) (<= (1+ o) k))
                                  (setf (aref dp b k u r (1+ o)) (max (aref dp b k u r (1+ o)) now)))
                            (when (and (or (char= c #\I) (char= c #\?)) (<= (1+ now) o))
                                  (setf (aref dp b k u r o) (max (aref dp b k u r o) (1+ now))))))))))
          (rotatef a b))
    (dotimes (k 21)
      (dotimes (u (1+ k))
        (dotimes (r (1+ u))
          (dotimes (o (1+ r))
            (setq res (max res (aref dp a k u r o)))))))
    (format t "~d~%" res)))

(main)
0