結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2015-11-12 03:19:18 |
言語 | OCaml (5.2.1) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 1,029 bytes |
コンパイル時間 | 409 ms |
コンパイル使用メモリ | 19,700 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-08 23:39:55 |
合計ジャッジ時間 | 1,231 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
let string_to_list str n cut =if n = 1 then [int_of_string str]elselet rec move_element pos ls =if List.length ls = n - 1 thenlet last_int = int_of_string (String.sub str (pos + 1) ((String.length str - 1) - pos)) inlast_int :: lselselet pos1 = String.index_from str (pos + 1) cut inlet strint = String.sub str (pos + 1) (pos1 - pos - 1) inlet int = int_of_string strint inlet newls = int :: ls inmove_element pos1 newlsinlet first_pos = String.index_from str 0 cut inlet first_int = int_of_string (String.sub str 0 first_pos) inmove_element first_pos [first_int]let median n ls =let ls_sorted = List.fast_sort compare ls inif n mod 2 = 0 then(float_of_int ((List.nth ls_sorted ((n/2) - 1)) + (List.nth ls_sorted ((n/2 + 1) - 1)))) /. 2.elsefloat_of_int (List.nth ls_sorted (((n + 1) / 2) - 1))let () =let n = int_of_string (read_line ()) inlet args = read_line () inprint_float (median n (string_to_list args n ' '));print_string "\n"