提出 #5882784


ソースコード 拡げる

(* O(h w) *)
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let q = Queue.create ()
let ds = Array.make_matrix h w @@ -1
let a_ss = Array.init h @@ fun i -> Array.init w @@ fun j -> Scanf.scanf " %c" @@ fun a ->
  if a = '#' then (ds.(i).(j) <- 0; Queue.push (i, j) q); a
let ans = ref 0
let _ =
  while not @@ Queue.is_empty q do
    let y0, x0 = Queue.pop q in
    let f (dy, dx) =
      let y, x = y0 + dy, x0 + dx in
      if 0 <= y && y < h && 0 <= x && x < w && ds.(y).(x) = -1 then
        (ans := ds.(y0).(x0) + 1; ds.(y).(x) <- !ans; Queue.push (y, x) q) in
    List.iter f [-1, 0; 0, -1; 1, 0; 0, 1]
  done;
  Printf.printf "%d\n" !ans

提出情報

提出日時
問題 A - Darker and Darker
ユーザ lbr
言語 OCaml (4.02.3)
得点 300
コード長 665 Byte
結果 AC
実行時間 298 ms
メモリ 69824 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 17
セット名 テストケース
Sample sample01.txt, sample02.txt
All sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, sample01.txt, sample02.txt
ケース名 結果 実行時間 メモリ
in01.txt AC 267 ms 59840 KiB
in02.txt AC 275 ms 62144 KiB
in03.txt AC 261 ms 62784 KiB
in04.txt AC 298 ms 69824 KiB
in05.txt AC 1 ms 384 KiB
in06.txt AC 263 ms 34428 KiB
in07.txt AC 268 ms 34300 KiB
in08.txt AC 264 ms 34300 KiB
in09.txt AC 272 ms 34300 KiB
in10.txt AC 115 ms 16256 KiB
in11.txt AC 98 ms 16384 KiB
in12.txt AC 106 ms 16256 KiB
in13.txt AC 106 ms 16384 KiB
sample01.txt AC 1 ms 384 KiB
sample02.txt AC 1 ms 384 KiB