結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
guricerin
|
| 提出日時 | 2020-02-05 16:50:30 |
| 言語 | F# (F# 4.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,418 bytes |
| コンパイル時間 | 9,450 ms |
| コンパイル使用メモリ | 189,596 KB |
| 実行使用メモリ | 40,592 KB |
| 最終ジャッジ日時 | 2024-09-22 16:11:22 |
| 合計ジャッジ時間 | 13,469 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 17 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (290 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/
ソースコード
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()
guricerin