結果

問題 No.871 かえるのうた
ユーザー ducktail
提出日時 2019-10-07 13:41:44
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 27,004 KB
最終ジャッジ日時 2024-11-30 10:57:03
合計ジャッジ時間 6,547 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (solve n k vx va)
  (let loop ([il (- k 1)]
             [ir (- k 1)]
             [rl (- (vector-ref vx (- k 1)) (vector-ref va (- k 1)))]
             [rr (+ (vector-ref vx (- k 1)) (vector-ref va (- k 1)))])
    (let* ([nir (+ ir 1)]
           [nil (- il 1)]
           [rfir (and (> n nir) (>= rr (vector-ref vx nir)))]
           [lfir (and (<= 0 nil) (<= rl (vector-ref vx nil)))])
      (cond [(and rfir lfir) (loop
                              nil
                              nir
                              (min rl
                                   (- (vector-ref vx nil) (vector-ref va nil))
                                   (- (vector-ref vx nir) (vector-ref va nir)))
                              (max rr
                                   (+ (vector-ref vx nir) (vector-ref va nir))
                                   (+ (vector-ref vx nil) (vector-ref va nil))))]
            [rfir (loop
                   il
                   nir
                   (min rl
                        (- (vector-ref vx nir) (vector-ref va nir)))
                   (max rr
                        (+ (vector-ref vx nir) (vector-ref va nir))))]
            [lfir (loop
                   nil
                   ir
                   (min rl
                        (- (vector-ref vx nil) (vector-ref va nil)))
                   (max rr
                        (+ (vector-ref vx nil) (vector-ref va nil))))]
            [else (- ir il -1)])
      )))

(define (main args)
  (let* ([n (read)]
         [k (read)]
         [vx (vector-tabulate n (^_ (read)))]
         [va (vector-tabulate n (^_ (read)))])
    (print (solve n k vx va)))
  0)
0