結果

問題 No.617 Nafmo、買い出しに行く
ユーザー ducktail
提出日時 2017-12-18 22:06:31
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 1,061 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 31,616 KB
最終ジャッジ日時 2024-12-16 00:53:05
合計ジャッジ時間 7,559 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (get-max-weight v k)
  (let loop ([i k])
    (cond [(= 1 (vector-ref v i)) i]
          [else (loop (- i 1))])))

(define (set-weight v k x)
  (let loop ([i k])
    (cond [(< i 0) #t]
          [else (if (and (= 1 (vector-ref v i))
                         (>= k (+ i x)))
                    (vector-set! v (+ i x) 1))
                (loop (- i 1))])))

(define (main args)
  (let* ([n (read)]
         [k (read)]
         [v (make-vector (+ k 1) 0)])
    (vector-set! v 0 1)
    (let loop ([c n])
      (cond [(zero? c) #t]
            [else (set-weight v k (read))
                  (loop (- c 1))]))
    (print (get-max-weight v k)))
  0)
0