結果

問題 No.482 あなたの名は
ユーザー tak
提出日時 2018-04-24 09:33:17
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 714 bytes
コンパイル時間 6,814 ms
コンパイル使用メモリ 203,488 KB
実行使用メモリ 52,240 KB
最終ジャッジ日時 2024-06-27 15:51:36
合計ジャッジ時間 10,803 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (237 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/

ソースコード

diff #

let stepCountToSort (arr:int[]) =
    let cnt = ref 0
    let swap a b = 
        let t = arr.[a]
        arr.[a] <- arr.[b]
        arr.[b] <- t
                
    for i in 1..arr |> Array.length do
        let idx = i-1
        if i <> arr.[idx] then
            //arr.[idx]が本来あるべき位置
            let rightIdx = arr.[idx]-1                    
            swap idx rightIdx  
            incr cnt
    cnt.Value    

let N,K = let t = stdin.ReadLine().Split() 
          in t.[0] |> int, t.[1] |> int64
let D   = stdin.ReadLine().Split() |> Array.map int
               
D
|> stepCountToSort
|> int64
|> function
    | x when x<=K && (K-x)%2L=0L -> "YES"
    | _ -> "NO"
|> printfn "%s"        
0