結果
問題 | No.14 最小公倍数ソート |
ユーザー | pocarist |
提出日時 | 2015-10-07 13:09:59 |
言語 | F# (F# 4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,893 bytes |
コンパイル時間 | 4,874 ms |
コンパイル使用メモリ | 168,672 KB |
実行使用メモリ | 44,884 KB |
最終ジャッジ日時 | 2023-09-27 07:43:43 |
合計ジャッジ時間 | 13,124 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 106 ms
27,908 KB |
testcase_01 | AC | 108 ms
23,536 KB |
testcase_02 | AC | 110 ms
23,716 KB |
testcase_03 | AC | 1,209 ms
44,884 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved.
ソースコード
// http://yukicoder.me/problems/38 open System open System.Collections.Generic let dpfn fmt = Printf.kprintf Diagnostics.Debug.WriteLine fmt let factors n = let i = ref 2 let tmp = ref n seq { while !i * !i <= n do if !tmp % !i = 0 then tmp := !tmp / !i yield !i else incr i if !tmp <> 1 then yield !tmp } [<EntryPoint>] let main argv = let add k m = match Map.tryFind k m with | None -> 0 | Some x -> x |> fun v -> Map.add k (v+1) m let merge a b = Map.fold (fun a' bk bv -> match Map.tryFind bk a' with | None -> Map.add bk bv a' | Some av -> Map.add bk (max av bv) a' ) a b let pow (a : int) b = bigint.Pow(bigint a, b) let lcm a b = merge a b |> Map.fold (fun s k v -> s * pow k v) 1I let lcmsort xs = let rec f acc = function | [] -> List.rev acc | (a,m) :: ax -> let ax' = ax |> List.map (fun (i,j) -> lcm m j, i, j) |> List.sort // |> fun x -> x |> List.map (fun (k,i,j) -> string (k,i,j)) |> String.concat " " |> dpfn "%s"; x |> List.map (fun (_,i,j) -> i,j) f (a :: acc) ax' f [] xs let N = Console.ReadLine().Trim() |> int let A = Console.ReadLine().Trim().Split([|' '|]) |> Array.map int A |> List.ofArray |> List.map (fun a -> a, factors a) // |> fun x -> dpfn "%A" x; x |> List.map (fun (a,fs) -> a, fs |> Seq.fold (fun m t -> add t m) Map.empty) // |> fun x -> dpfn "%A" x; x |> lcmsort |> List.map string |> String.concat " " |> printfn "%s" 0 // 整数の終了コードを返します