結果

問題 No.455 冬の大三角
ユーザー ducktail
提出日時 2017-09-09 15:37:37
言語 OCaml
(5.2.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 21,712 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 00:29:32
合計ジャッジ時間 1,949 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

open Printf
open Scanf

let find ar h w =
  let rec iter i j ps = 
    if i = h then ps
    else if j = w then iter (i+1) 0 ps
    else if ar.(i).[j] = '*' then iter i (j+1) ((i,j) :: ps)
    else iter i (j+1) ps in
  iter 0 0 []
       
let print_tbl ar w x y =
  Array.iteri (fun i s ->
               if i = x then printf "%s\n" (String.init w (fun j -> if j = y then '*' else s.[j]))
               else printf "%s\n" s) ar

let () =
  let h, w = scanf "%d %d " (fun x y -> (x, y)) in
  let tbl = Array.init h (fun _ -> let s = scanf "%s " (fun x -> x) in s) in
  match find tbl h w with
    (x1, y1) :: (x2, y2) :: _ -> begin
      let rec loop i j =
        if j = w then loop (i+1) 0
        else if (x1-i) * (y2-j) - (y1-j) * (x2-i) = 0 then loop i (j+1)
        else print_tbl tbl w i j in
      loop 0 0
    end
  | _ -> failwith "find"
0