Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- mas = ['#' * (n + 2)]
- for i in range(n):
- s = input()
- mas.append('#' + s + '#')
- mas.append('#' * (n + 2))
- used = [[False] * (n + 2) for i in range(n + 2)]
- def dfs(i,j):
- a = [(0, 1), (0, -1), (1, 0), (-1, 0)]
- for q in a:
- x, y = i + q[0], j + q[1]
- if mas[x][y] == '.' and not used[x][y]:
- used[x][y] = True
- dfs(x, y)
- dfs(1,1)
- def cnt(i, j):
- count = 0
- a = [(0, 1), (0, -1), (1, 0), (-1, 0)]
- for q in a:
- x, y = i + q[0], j + q[1]
- #if i == 1 and j == 4:
- #print(x, y, mas[x][y])
- if mas[x][y] == '#':
- count += 1
- #if count > 0:
- #print(count ,i, j)
- return count
- k = 0
- for i in range(1, n + 1):
- for j in range(1, n + 1):
- if used[i][j]:
- k += cnt(i, j)
- print((k - 4) * 9)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement