結果

問題 No.26 シャッフルゲーム
ユーザー ichibanshiboriichibanshibori
提出日時 2016-10-25 16:20:09
言語 OCaml
(5.1.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 628 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 15,900 KB
最終ジャッジ日時 2023-07-30 07:01:26
合計ジャッジ時間 614 ms
ジャッジサーバーID
(参考情報)
judge5 / judge13
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
File "Main.ml", line 3, characters 2-13:
3 |   Stream.iter (fun x -> result := f !result x) stream;
      ^^^^^^^^^^^
Error: Unbound module Stream

ソースコード

diff #

let stream_fold f stream init =
  let result = ref init in
  Stream.iter (fun x -> result := f !result x) stream;
  !result

let swap curPos (p, q) =
  match curPos = p, curPos = q with
  | true, false -> q
  | false, true -> p
  | _, _ -> curPos

let () =
  let n = read_line () |> int_of_string
  and m = read_line () |> int_of_string
  in
  let inSeq = Stream.from (fun i ->
    if i < m then
      read_line () |>
      Str.split (Str.regexp_string " ") |>
      List.map int_of_string |>
      fun lst -> Some (List.nth lst 0, List.nth lst 1)
    else None)
  in
  stream_fold swap inSeq n |> string_of_int |> print_endline
0