Created
October 11, 2017 01:56
-
-
Save whatalnk/4aed52aaec5f54f409711ef021d56aed to your computer and use it in GitHub Desktop.
AtCoder ARC #031 B - 埋め立て
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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