結果

問題 No.927 Second Permutation
ユーザー guriceringuricerin
提出日時 2020-02-05 16:50:30
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 1,418 bytes
コンパイル時間 18,346 ms
コンパイル使用メモリ 189,496 KB
実行使用メモリ 39,988 KB
最終ジャッジ日時 2023-10-23 22:57:39
合計ジャッジ時間 26,551 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
33,488 KB
testcase_01 AC 90 ms
34,520 KB
testcase_02 AC 67 ms
33,116 KB
testcase_03 AC 67 ms
33,116 KB
testcase_04 AC 68 ms
33,116 KB
testcase_05 AC 81 ms
34,320 KB
testcase_06 AC 80 ms
34,320 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 104 ms
38,968 KB
testcase_25 AC 98 ms
37,620 KB
testcase_26 AC 96 ms
36,964 KB
testcase_27 AC 85 ms
35,684 KB
testcase_28 AC 91 ms
38,300 KB
testcase_29 AC 90 ms
37,480 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (687 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/

ソースコード

diff #

open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let xs = readInts() |> Array.sortDescending
    let ng = xs |> Array.forall (fun x -> x = xs.[0])
    if ng then
        printfn "-1"
        exit 0

    let ys = xs |> Array.skipWhile (fun x -> x = xs.[0])
    let head = xs |> Array.takeWhile (fun x -> x = xs.[0])
    let same = ys |> Array.forall (fun y -> y = ys.[0])

    let ys =
        if same then
            let t = head.[0]
            head.[0] <- ys.[0]
            ys.[0] <- t
            Array.append head ys
        else
            let yh = ys |> Array.takeWhile (fun y -> y = ys.[0])
            let yt = ys |> Array.skipWhile (fun y -> y = ys.[0])
            let t = yh.[0]
            yh.[0] <- yt.[0]
            yt.[0] <- t
            Array.concat [| head; yh; yt |]

    if ys.[0] = 0 then puts -1 else String.Join("", ys) |> puts
    ()

main()
writer.Close()
0