結果

問題 No.82 市松模様
ユーザー ichibanshiboriichibanshibori
提出日時 2016-12-26 19:14:36
言語 OCaml
(5.1.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,147 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 16,144 KB
最終ジャッジ日時 2023-07-30 07:02:11
合計ジャッジ時間 845 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

ソースコード

diff #

let readln_t3_str () =
  let ( @@ ) lst n = List.nth lst n in
  read_line () |>
  Str.split (Str.regexp_string " ") |>
  fun lst -> (lst @@ 0, lst @@ 1, lst @@ 2)

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

let stream_concat sep str_st =
  match Stream.peek str_st with
  | None -> ""
  | Some(_) ->
    let result = ref (Stream.next str_st) in
    Stream.iter (fun str -> result := !result ^ sep ^ str) str_st;
    !result



let solve w h c =
  let c_arr = if c = "B" then [| "B"; "W"; |]
                         else [| "W"; "B"; |]
  in
  let make_line y =
    let ymod2 = y mod 2 in
    let rec make_line' x result =
      if x >= w then result
      else
        let c_idx = (x + ymod2) mod 2 in
        make_line' (x + 1) (result ^ c_arr.(c_idx))
    in
    make_line' 0 ""
  in
  let line_st =
    Stream.from (fun y -> if y >= h then None else Some(make_line y))
  in
  stream_concat "\n" line_st

let () =
  let w, h, c = readln_t3_str () |>
                fun (t1, t2, t3) -> (int_of_string t1, int_of_string t2, t3)
  in
  solve w h c |> print_endline
0