結果
| 問題 | No.70 睡眠の重要性! | 
| コンテスト | |
| ユーザー |  Common Lisp | 
| 提出日時 | 2024-10-07 19:38:09 | 
| 言語 | Common Lisp (sbcl 2.5.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 9 ms / 5,000 ms | 
| コード長 | 1,903 bytes | 
| コンパイル時間 | 1,227 ms | 
| コンパイル使用メモリ | 38,672 KB | 
| 実行使用メモリ | 29,884 KB | 
| 最終ジャッジ日時 | 2024-10-07 19:38:11 | 
| 合計ジャッジ時間 | 1,057 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 6 | 
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 07 OCT 2024 07:38:09 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.089
ソースコード
; 24時間以上寝続けないので
; (a = 起きた時(分)) >= (b = 寝た時(分))
; なら a - b それ以外なら (24 * 60 + b) - a
; 記録し足す
; 時刻 HH:MM の 00:00 からの経過分を求める関数
(defun g (hh mm)
  (+ (* hh 60) mm))
; "HH1:MM1 HH2:MM2" 形式で与えられた睡眠時間HH1:MM1と起床時間HH2:MM2を経過分数に直す関数
(defun f (s)
  (let*
    (
      ; position item sequence &key from-end test test-not start end key => position
      ; position 関数は sequence 中で item が存在する場所を0スタートで返す
      ; from-end の値が true のとき後ろから検索する
      ; sp 空白位置
      (sp (position #\space s))
      ; c1 寝る時間のコロンの位置 
      (c1 (position #\: s))
      ; c2 起きる時間のコロンの位置
      (c2 (position #\: s :from-end t))
      ; read-from-string string &optional eof-error-p eof-value &key start end preserve-whitespace => object, position
      ; read-from-string 関数は文字列を引数として受け取り
      ; start から end までの部分Lispオブジェクトを得ることができる (デフォルトはstart=0, end=nilで全文字列)
      ; eof-error-p を t, eof-value を nil にすることで返り値として eof を返させない
      ; 余計な空白は無いと考えるので preserve-whitespace は false (つまりデフォルト)とする
      (bedtime (g (read-from-string s t nil :end c1) (read-from-string s t nil :start (1+ c1) :end sp)))
      (wake-up-time (g (read-from-string s t nil :start (1+ sp) :end c2) (read-from-string s t nil :start (1+ c2))))
    )
    (if (> bedtime wake-up-time)
      (- (+ 1440 wake-up-time) bedtime)
      (- wake-up-time bedtime))))
(defun main ()
  (let* ((n (read))
         (ans 0))
    (dotimes (_ n)
      (incf ans (f (read-line))))
    (princ ans)
    (terpri)))
(main)
            
            
            
        