結果
問題 | No.39 桁の数字を入れ替え |
ユーザー | tak |
提出日時 | 2019-07-04 15:32:09 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 85 ms / 5,000 ms |
コード長 | 1,188 bytes |
コンパイル時間 | 8,142 ms |
コンパイル使用メモリ | 193,660 KB |
実行使用メモリ | 31,568 KB |
最終ジャッジ日時 | 2023-10-19 07:38:07 |
合計ジャッジ時間 | 10,846 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
31,492 KB |
testcase_01 | AC | 80 ms
31,548 KB |
testcase_02 | AC | 82 ms
31,492 KB |
testcase_03 | AC | 84 ms
31,564 KB |
testcase_04 | AC | 85 ms
31,564 KB |
testcase_05 | AC | 82 ms
31,564 KB |
testcase_06 | AC | 82 ms
31,564 KB |
testcase_07 | AC | 82 ms
31,564 KB |
testcase_08 | AC | 80 ms
31,492 KB |
testcase_09 | AC | 78 ms
31,492 KB |
testcase_10 | AC | 83 ms
31,544 KB |
testcase_11 | AC | 80 ms
31,568 KB |
testcase_12 | AC | 84 ms
31,564 KB |
testcase_13 | AC | 83 ms
31,568 KB |
testcase_14 | AC | 82 ms
31,568 KB |
testcase_15 | AC | 82 ms
31,564 KB |
testcase_16 | AC | 81 ms
31,564 KB |
testcase_17 | AC | 79 ms
31,564 KB |
testcase_18 | AC | 79 ms
31,564 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (244 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 solve n = let num2list n = (string n).ToCharArray() |> Array.map (string >> int) |> Array.toList let rec list2str (acc : StringBuilder) = function | [] -> acc.ToString() | x :: xs -> list2str (acc.Append(string x)) xs let rec f (acc : StringBuilder) xs = match xs with | [] -> acc.ToString() | y :: ys -> let xsMax = xs |> List.max if y = xsMax then f (acc.Append(string y)) ys else let swapRightIdx = ys |> List.indexed |> List.findBack (fun (_, x) -> x = xsMax) |> fun (idx, _) -> idx let ys' = ys |> List.mapi (fun i v -> match i with | _ when i = swapRightIdx -> y | _ -> v) list2str (acc.Append(string ys.[swapRightIdx])) ys' n |> num2list |> f (new StringBuilder()) let N = int <| Console.ReadLine() solve N |> Console.WriteLine