結果
| 問題 |
No.9 モンスターのレベル上げ
|
| コンテスト | |
| ユーザー |
pocarist
|
| 提出日時 | 2015-09-11 16:22:16 |
| 言語 | F# (F# 4.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,028 bytes |
| コンパイル時間 | 6,470 ms |
| コンパイル使用メモリ | 200,068 KB |
| 実行使用メモリ | 61,440 KB |
| 最終ジャッジ日時 | 2024-07-19 05:16:54 |
| 合計ジャッジ時間 | 14,154 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 17 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (199 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
// 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 0
for i in 0..N-1 do
let rec loop h j =
if j=N then h
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 (j+1)
let h = loop start 0
let rec f m h =
if Heap.empty h then m else
let (_, n) = Heap.top h
f (max n m) (Heap.pop h)
let m = f 0 h
ans := max m !ans
printfn "%d" !ans
0
pocarist