SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2. mas = ['#' * (n + 2)]
  3. for i in range(n):
  4.     s = input()
  5.     mas.append('#' + s + '#')
  6. mas.append('#' * (n + 2))
  7.  
  8. used = [[False] * (n + 2) for i in range(n + 2)]
  9. def dfs(i,j):
  10.     a = [(0, 1), (0, -1), (1, 0), (-1, 0)]
  11.     for q in a:
  12.         x, y = i + q[0], j + q[1]
  13.         if mas[x][y] == '.' and not used[x][y]:
  14.             used[x][y] = True
  15.             dfs(x, y)
  16. dfs(1,1)
  17. def cnt(i, j):
  18.     count = 0                            
  19.     a = [(0, 1), (0, -1), (1, 0), (-1, 0)]
  20.     for q in a:
  21.         x, y = i + q[0], j + q[1]
  22.         #if i == 1 and j == 4:
  23.                 #print(x, y, mas[x][y])
  24.         if mas[x][y] == '#':
  25.            
  26.             count += 1
  27.     #if count > 0:
  28.        #print(count ,i, j)
  29.        
  30.     return count
  31.  
  32. k = 0
  33. for i in range(1, n + 1):
  34.     for j in range(1, n + 1):
  35.         if used[i][j]:
  36.             k += cnt(i, j)
  37.    
  38. print((k - 4) * 9)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top