結果
問題 |
No.1416 ショッピングモール
|
ユーザー |
|
提出日時 | 2021-06-02 07:18:52 |
言語 | OCaml (5.2.1) |
結果 |
AC
|
実行時間 | 26 ms / 1,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 1,321 ms |
コンパイル使用メモリ | 19,824 KB |
実行使用メモリ | 9,876 KB |
最終ジャッジ日時 | 2024-11-14 05:05:26 |
合計ジャッジ時間 | 2,148 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
let split_on_char sep s = let r = ref [] in let j = ref (String.length s) in for i = String.length s - 1 downto 0 do if String.unsafe_get s i = sep then begin r := String.sub s (i + 1) (!j - i - 1) :: !r; j := i end done; String.sub s 0 !j :: !r;; let pow x y = let rec inner_pow i result = match i with | 0 -> result | _ -> inner_pow (i - 1) (result * x) in inner_pow y 1;; let rec shop_tumeru cost k hairu lst = match lst with | [] -> cost | _ -> let max_k = pow 2 k in if (hairu >= max_k) then shop_tumeru cost (k + 1) 0 lst else let next_shop = List.hd lst in let lst = List.tl lst in let cost = cost + (next_shop * k) in let hairu = hairu + 1 in shop_tumeru cost k hairu lst;; let () = read_line () |> ignore; let lst = read_line () |> split_on_char ' ' |> List.map int_of_string |> List.fast_sort (fun x y -> - ( compare x y)) in shop_tumeru 0 0 0 lst |> print_int; print_newline ();;