結果
| 問題 |
No.203 ゴールデン・ウィーク(1)
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-10-08 15:40:16 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 1,000 ms |
| コード長 | 1,519 bytes |
| コンパイル時間 | 365 ms |
| コンパイル使用メモリ | 37,628 KB |
| 実行使用メモリ | 31,892 KB |
| 最終ジャッジ日時 | 2024-10-08 15:40:19 |
| 合計ジャッジ時間 | 1,789 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 08 OCT 2024 03:40:16 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.042
ソースコード
; 文字列を一度全て繋げる
; その後リストに矯正し group 化して最大個数を調べる
; 隣接する同一要素をまとめたリストをリスト化する
; (group '(1 2 2 1 2 2 1 1 1 1 2 2 1 2 2))
; =>
; ((1) (2 2) (1) (2 2) (1 1 1 1) (2 2) (1) (2 2))
(defun group (lst)
(let ((result '())
(cur nil))
(dolist (c lst)
(if (null cur)
(setq cur (list c))
(if (equal c (car cur))
(push c cur)
(progn
(push (nreverse cur) result)
(setq cur (list c))))))
(when cur
(push (nreverse cur) result))
(nreverse result)))
(defun main ()
; 読み込んだ一行の文字列を組み合わせる
(let* ((s (concatenate 'string (read-line) (read-line)))
; 休みがない場合は別に処理する
; このとき 0 を出力する
(a (find #\o s)))
(if a
(princ
; リストの左から右へ2項ずつ最大値を求めながら走査していく
(reduce #'max
; 各リストの長さを求める
(map 'list #'length
; 平日のリストを除く
(remove-if (lambda (cs) (char= (car cs) #\x))
; 平日の連なりと休日の連なりを一つのリストにまとめ、それらをリスト化する関数
(group
; 文字列を強制的に一文字ずつのリストに変換する
(coerce s 'list))))))
(princ 0)))
(terpri))
(main)
Common Lisp