結果
問題 |
No.275 中央値を求めよ
|
ユーザー |
![]() |
提出日時 | 2015-09-22 05:37:07 |
言語 | Scheme (Gauche-0.9.15) |
結果 |
AC
|
実行時間 | 134 ms / 1,000 ms |
コード長 | 885 bytes |
コンパイル時間 | 72 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 33,536 KB |
最終ジャッジ日時 | 2024-06-24 23:19:34 |
合計ジャッジ時間 | 2,716 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#!/usr/bin/env gosh (define (read-input) (let ((n (read (open-input-string (read-line)))) (numbers (read (open-input-string (string-append "(" (read-line) ")"))))) (cons n numbers))) (define (sort lst) (define (filter p? lst acc) (if (null? lst) acc (if (p? (car lst)) (filter p? (cdr lst) (cons (car lst) acc)) (filter p? (cdr lst) acc)))) (if (null? lst) '() (append (sort (filter (lambda (x) (<= (car lst) x)) (cdr lst) '())) (list (car lst)) (sort (filter (lambda (x) (> (car lst) x)) (cdr lst) '()))))) (define (get-median lst) (let ((n (car lst)) (ns (sort (cdr lst)))) (if (even? n) (* 0.5 (+ (list-ref ns (/ n 2)) (list-ref ns (- (/ n 2) 1)))) (list-ref ns (div n 2))))) (display (get-median (read-input))) (newline)