Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 12, 2017 13:47
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/f0f99dcba53cd3253f744b98cf16be06 to your computer and use it in GitHub Desktop.
Save whatalnk/f0f99dcba53cd3253f744b98cf16be06 to your computer and use it in GitHub Desktop.
AtCoder ARC #038 B - マス目と駒
H, W = gets.chomp.split(" ").map(&:to_i)
@m = []
H.times do
@m << gets.chomp.split("")
end
@memo = Array.new(H){Array.new(W)}
def judge(i, j)
return 1 if i < 0 || i >= H || j < 0 || j >= W || @m[i][j] == "#"
return @memo[i][j] if !@memo[i][j].nil?
result = -1
result = 1 if judge(i + 1, j) == -1
result = 1 if judge(i, j + 1) == -1
result = 1 if judge(i + 1, j + 1) == -1
@memo[i][j] = result
return result
end
if judge(0, 0) > 0
puts "First"
else
puts "Second"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment