ababup1192
9/18/2016 - 3:58 PM

http://abc018.contest.atcoder.jp/submissions/885000

r, c, k = gets.split.map(&:to_i)
 
k -= 1
 
queue = []

min_dist = (0..r-1).map{|i|
  gets.chomp.chars.map.with_index{|mark, j|
    # ↓本当はやりたくない。
    queue << [i, j]
    mark == 'x' ? 0 : r * c
  }
}

#### リファクタリング後
#### リファクタリング前

dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
until queue.empty? do
  y, x = queue.shift
  # 4.times do |i|
  dxy.each do |dy, dx|
    ny = y + dy
    nx = x + dx
    # ny = y + dy[i]
    # nx = x + dx[i]
    # next unless ny.between?(0, r - 1)
    # next unless nx.between?(0, c - 1)
    next unless 0 <= ny && ny < r
    next unless 0 <= nx && nx < c
    next unless min_dist[ny][nx] > min_dist[y][x] + 1
    min_dist[ny][nx] = min_dist[y][x] + 1
    next unless min_dist[ny][nx] < k
    queue << [ny, nx]
  end
end

ans = 0
# for i in k...(r - k) do
#   for j in k...(c - k) do
#     ans += 1 if min_dist[i][j] > k
#   end
# end

for i in k...(r - k) do
  ans += min_dist[i][k...(c - k)].count { |v| v > k }
end

puts ans