結果
問題 | No.9 モンスターのレベル上げ |
ユーザー | pocarist |
提出日時 | 2015-09-15 13:05:07 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 2,777 ms / 5,000 ms |
コード長 | 1,955 bytes |
コンパイル時間 | 6,276 ms |
コンパイル使用メモリ | 177,532 KB |
実行使用メモリ | 42,884 KB |
最終ジャッジ日時 | 2023-09-06 04:17:30 |
合計ジャッジ時間 | 28,068 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
22,976 KB |
testcase_01 | AC | 87 ms
23,172 KB |
testcase_02 | AC | 2,777 ms
42,884 KB |
testcase_03 | AC | 1,237 ms
33,420 KB |
testcase_04 | AC | 1,177 ms
32,780 KB |
testcase_05 | AC | 873 ms
29,124 KB |
testcase_06 | AC | 327 ms
27,456 KB |
testcase_07 | AC | 94 ms
23,228 KB |
testcase_08 | AC | 352 ms
27,476 KB |
testcase_09 | AC | 2,500 ms
38,408 KB |
testcase_10 | AC | 82 ms
23,064 KB |
testcase_11 | AC | 1,828 ms
32,856 KB |
testcase_12 | AC | 717 ms
27,576 KB |
testcase_13 | AC | 109 ms
27,668 KB |
testcase_14 | AC | 2,450 ms
38,660 KB |
testcase_15 | AC | 2,621 ms
41,436 KB |
testcase_16 | AC | 127 ms
29,296 KB |
testcase_17 | AC | 1,734 ms
37,832 KB |
testcase_18 | AC | 1,460 ms
32,116 KB |
testcase_19 | AC | 120 ms
29,508 KB |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved.
ソースコード
// http://yukicoder.me/problems/26 open System let dprintfn fmt = Printf.kprintf Diagnostics.Debug.WriteLine fmt module Heap = type tree<'T> = Node of 'T * tree<'T> * tree<'T> | Leaf type t<'T> = { root : tree<'T> cmp : 'T -> 'T -> bool } let create cmp = {root=Leaf; cmp=cmp} let rec meld cmp a b = match a, b with | Leaf, _ -> b | _, Leaf -> a | Node(av, al, ar), Node(bv, bl, br) -> if cmp av bv then let br = meld cmp br a Node(bv, br, bl) else let ar = meld cmp ar b Node(av, ar, al) let push v h = let p = Node(v, Leaf, Leaf) let r = meld h.cmp h.root p {h with root=r} let empty h = h.root = Leaf let top h = match h.root with | Leaf -> failwith "top" | Node(v, _, _) -> v let pop h = match h.root with | Leaf -> failwith "pop" | Node(_, rl, rr) -> let r = meld h.cmp rr rl {h with root=r} [<EntryPoint>] let main argv = let N = Console.ReadLine().Trim() |> int let A = Console.ReadLine().Trim().Split([|' '|]) |> Array.map int let B = Console.ReadLine().Trim().Split([|' '|]) |> Array.map int let h = Heap.create (>) let start = Array.fold (fun h v -> Heap.push (v,0) h) h A let ans = ref (Int32.MaxValue/2) for i in 0..N-1 do let rec loop h tmp j = if j=N then tmp else if tmp >= !ans then tmp else let (v, n) = Heap.top h let h = Heap.pop h let k = (i+j)%N let v' = B.[k] / 2 let h = Heap.push (v+v', n+1) h loop h (max tmp (n+1)) (j+1) let tmp = loop start 0 0 ans := min tmp !ans printfn "%d" !ans 0