結果

問題 No.482 あなたの名は
ユーザー taktak
提出日時 2018-04-24 09:37:02
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 712 bytes
コンパイル時間 3,332 ms
コンパイル使用メモリ 156,456 KB
実行使用メモリ 46,768 KB
最終ジャッジ日時 2023-09-09 23:25:51
合計ジャッジ時間 9,285 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
24,676 KB
testcase_01 AC 83 ms
22,568 KB
testcase_02 AC 83 ms
20,684 KB
testcase_03 AC 81 ms
20,676 KB
testcase_04 AC 81 ms
20,640 KB
testcase_05 AC 83 ms
24,680 KB
testcase_06 AC 82 ms
24,644 KB
testcase_07 AC 91 ms
22,896 KB
testcase_08 WA -
testcase_09 AC 89 ms
22,820 KB
testcase_10 AC 93 ms
24,748 KB
testcase_11 AC 92 ms
22,852 KB
testcase_12 WA -
testcase_13 AC 92 ms
22,904 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 194 ms
44,748 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 191 ms
44,708 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 191 ms
46,768 KB
testcase_24 AC 191 ms
42,668 KB
testcase_25 AC 190 ms
42,628 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 190 ms
42,748 KB
testcase_29 AC 189 ms
44,764 KB
testcase_30 AC 83 ms
20,576 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

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 && x%2L=K%2L -> "YES"
    | _ -> "NO"
|> printfn "%s"        
0