Scanf.scanf "%d %d %s" (fun n m s -> let mat = Array.make_matrix (n + 1) (n + 1) 1 in mat.(n).(0) <- 0; let rec loop i x y = if i = m then mat else let x = if s.[i] = 'L' then x - 1 else if s.[i] = 'R' then x + 1 else x in let y = if s.[i] = 'D' then y + 1 else if s.[i] = 'U' then y - 1 else y in let () = mat.(y).(x) <- 0 in loop (i + 1) x y in Array.iter (fun a -> Array.iter (Printf.printf "%d ") a; print_newline () ) @@ loop 0 0 n )