結果
問題 | No.39 桁の数字を入れ替え |
ユーザー | tak |
提出日時 | 2019-07-04 15:25:17 |
言語 | F# (F# 4.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,365 bytes |
コンパイル時間 | 7,966 ms |
コンパイル使用メモリ | 194,004 KB |
実行使用メモリ | 38,996 KB |
最終ジャッジ日時 | 2023-10-19 07:37:28 |
合計ジャッジ時間 | 11,918 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 76 ms
31,668 KB |
testcase_02 | RE | - |
testcase_03 | AC | 76 ms
31,688 KB |
testcase_04 | AC | 76 ms
31,696 KB |
testcase_05 | AC | 78 ms
31,696 KB |
testcase_06 | AC | 78 ms
31,696 KB |
testcase_07 | AC | 78 ms
31,708 KB |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | AC | 78 ms
31,676 KB |
testcase_11 | AC | 79 ms
31,696 KB |
testcase_12 | AC | 78 ms
31,696 KB |
testcase_13 | AC | 75 ms
31,696 KB |
testcase_14 | AC | 75 ms
31,708 KB |
testcase_15 | AC | 77 ms
31,708 KB |
testcase_16 | AC | 76 ms
31,708 KB |
testcase_17 | AC | 75 ms
31,708 KB |
testcase_18 | AC | 77 ms
31,704 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (260 ms)。 MSBuild のバージョン 17.7.3+8ec440e68 (.NET) main -> /home/judge/data/code/bin/Release/net7.0/main.dll main -> /home/judge/data/code/bin/Release/net7.0/publish/
ソースコード
module Yuki open System open System.Text let inline ret x = Some x let inline (>>=) (m: Option<'a>) f = match m with | Some x -> f x | None -> None type MaybeBuilder () = member __.Return(x) = ret x member __.Bind(m, f) = m >>= f let maybe = MaybeBuilder () let solve n = let num2list n = let rec f acc n = if n < 10 then n :: acc else f (n % 10 :: acc) (n / 10) f [] n let rec list2str (acc : StringBuilder) = function | [] -> acc.ToString() | x :: xs -> list2str (acc.Append(string x)) xs let rec f (acc : StringBuilder) xs = let xsMax = xs |> List.max match xs with | x :: xs when x = xsMax -> f (acc.Append(string x)) xs | x :: xs -> let swapRightIdx = xs |> List.indexed |> List.findBack (fun (_, x) -> x = xsMax) |> fun (idx, _) -> idx let xs' = xs |> List.mapi (fun i v -> match i with | _ when i = swapRightIdx -> x | _ -> v) list2str (acc.Append(string xs.[swapRightIdx])) xs' | [] -> failwith "" n |> num2list |> f (new StringBuilder()) let N = int <| Console.ReadLine() solve N |> Console.WriteLine