結果

問題 No.482 あなたの名は
ユーザー ichibanshibori
提出日時 2017-02-11 01:37:01
言語 F#
(F# 4.0)
結果
RE  
実行時間 -
コード長 1,270 bytes
コンパイル時間 17,423 ms
コンパイル使用メモリ 186,800 KB
実行使用メモリ 59,456 KB
最終ジャッジ日時 2024-12-29 11:48:29
合計ジャッジ時間 15,216 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 RE * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (540 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 solve k darr =
    let len_darr = Array.length darr
    let chk_arr = Array.create len_darr false
    
    let rec get_len_loop start current result =
        chk_arr.[current] <- true

        let next = darr.[current]
        let result = current::result

        //eprintfn "get_len_loop: %A" (start, current, result)

        if next = start then (List.length result) - 1
        else
            get_len_loop start next result
    
    let rec get_len_loop_sum idx result =
        //eprintfn "get_len_loop_sum: %A" (idx, result)

        if idx >= len_darr then result
        else
            if chk_arr.[idx] then get_len_loop_sum (idx + 1) result
            else
                let len_loop = get_len_loop idx idx []
                get_len_loop_sum (idx + 1) (result + len_loop)

    let len_loop = get_len_loop_sum 0 0

    k >= len_loop && (k - len_loop) % 2 = 0

let () =
    let _, k = stdin.ReadLine()
               |> fun s -> s.Split()
               |> Array.map int
               |> fun arr -> (arr.[0], arr.[1])
    let darr = stdin.ReadLine()
               |> fun s -> s.Split()
               |> Array.map int
               |> Array.map (( + ) -1)
    
    solve k darr
    |> function | true -> "YES" | false -> "NO"
    |> printfn "%s"
0