結果
| 問題 | No.26 シャッフルゲーム | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-10-25 16:20:09 | 
| 言語 | OCaml (5.2.1) | 
| 結果 | 
                                CE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 628 bytes | 
| コンパイル時間 | 55 ms | 
| コンパイル使用メモリ | 17,024 KB | 
| 最終ジャッジ日時 | 2024-11-14 19:53:05 | 
| 合計ジャッジ時間 | 416 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
File "Main.ml", line 3, characters 2-13:
3 |   Stream.iter (fun x -> result := f !result x) stream;
      ^^^^^^^^^^^
Error: Unbound module Stream
            
            ソースコード
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
            
            
            
        