Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 11, 2017 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/4aed52aaec5f54f409711ef021d56aed to your computer and use it in GitHub Desktop.
Save whatalnk/4aed52aaec5f54f409711ef021d56aed to your computer and use it in GitHub Desktop.
AtCoder ARC #031 B - 埋め立て
n = 0
@m = Array.new()
10.times do
row = gets.chomp.split("")
n += row.count("o")
@m << row
end
def area(x, y)
@visited[y][x] = true
ret = 0
ret += 1 if @m[y][x] == 'o'
[[0, -1], [1, 0], [0, 1], [-1, 0]].each do |dx, dy|
nx = x + dx
ny = y + dy
if 0 <= nx && 10 > nx && 0 <= ny && 10 > ny && !@visited[ny][nx] && @m[ny][nx] == "o" then
ret += area(nx, ny)
end
end
return ret
end
10.times do |i|
10.times do |j|
@visited = Array.new(10){Array.new(10, false)}
if area(i, j) == n
puts "YES"
exit
end
end
end
puts "NO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment