結果

問題 No.482 あなたの名は
ユーザー taktak
提出日時 2018-04-24 09:46:07
言語 F#
(F# 4.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 15,946 ms
コンパイル使用メモリ 203,460 KB
実行使用メモリ 52,224 KB
最終ジャッジ日時 2024-06-27 15:52:14
合計ジャッジ時間 11,494 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (465 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
        while i <> arr.[idx] do            
            //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