結果

問題 No.482 あなたの名は
ユーザー tak
提出日時 2018-04-24 09:28:00
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 762 bytes
コンパイル時間 9,805 ms
コンパイル使用メモリ 196,480 KB
実行使用メモリ 52,224 KB
最終ジャッジ日時 2024-06-27 15:49:40
合計ジャッジ時間 14,924 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (243 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
|> function
    | 0 -> "YES"
    | x ->
        let x = x |> int64
        if x<=K && (K-x)%2L=0L then "YES"
        else "NO"
|> printfn "%s"        
0