結果

問題 No.116 門松列(1)
ユーザー Common Lisp
提出日時 2024-10-07 23:20:02
言語 Common Lisp
(sbcl 2.5.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 961 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 37,552 KB
実行使用メモリ 21,760 KB
最終ジャッジ日時 2024-10-07 23:20:04
合計ジャッジ時間 1,505 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 07 OCT 2024 11:20:02 PM):

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

ソースコード

diff #

; 左から3つずつ数字を取ってきて門松列になっているか判定する
(defun main ()
  (let* ((n (read))
              ; loop repeat で指定回数繰り返し collect で読み込んだ値のリストを作成できる
         (xs (loop repeat n collect (read)))
                                ; loop マクロ中で on xs を使うと xs の cdr を見ながらループできる
                                ; loop for (a b c) on '(1 2 3 4 5 6 7) とすると
                                ; (1 2 3) (2 3 4) (3 4 5) ... のようにループする
         (ans (loop for (a b c) on xs
                    ; c が nil になるまで続ける
                    while c
                    ; count 以下の式を満たす個数を求める
                    count (and (/= a b c)
                               (or (= b (min a b c))
                                   (= b (max a b c)))))))
    (princ ans)
    (terpri)))
(main)
0