Skip to content

Instantly share code, notes, and snippets.

@einblicker
Created July 15, 2012 03:45
Show Gist options
  • Save einblicker/3114828 to your computer and use it in GitHub Desktop.
Save einblicker/3114828 to your computer and use it in GitHub Desktop.
AOJ 0118 Property Distribution
let ringo = '@'
let kaki = '#'
let mikan = '*'
let loopEnd = ref false
while not !loopEnd do
let [|I; J|] = System.Console.ReadLine().Split([|' '|]) |> Array.map int
if I = 0 && J = 0 then
loopEnd := true
else
let maze =
[| for x = 0 to J - 1 do
yield System.Console.ReadLine().ToCharArray() |]
let count = ref 0
let rec dfs current i j =
if maze.[j].[i] = current then
maze.[j].[i] <- '.'
for (dj, di) in [ (-1, 0); (0, -1); (1, 0); (0, 1) ] do
if j+dj >= 0 && i+di >= 0 && j+dj < J && i + di < I && maze.[j+dj].[i+di] <> '.' then
if maze.[j+dj].[i+di] = current then
dfs current (i+di) (j+dj)
for i = 0 to I - 1 do
for j = 0 to J - 1 do
if maze.[j].[i] <> '.' then
incr count
dfs maze.[j].[i] i j
printfn "%A" !count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment