fork download
  1. import sys
  2.  
  3. def get_array(): return list(map(int, sys.stdin.readline().split()))
  4. def get_ints(): return map(int, sys.stdin.readline().split())
  5. def input(): return sys.stdin.readline().strip('\n')
  6.  
  7.  
  8. visited = []
  9. out = []
  10.  
  11. for i in range(1010):
  12. visited.append([])
  13. out.append([])
  14. for j in range(1010):
  15. visited[i].append(0)
  16. out[i].append(-1)
  17. cells = []
  18. def dfs(x,y):
  19. global c
  20. if x >= n or x < 0 or y >= m or y < 0:
  21. return
  22. if l[x][y] == '*':
  23. c += 1
  24. return
  25. if visited[x][y] :
  26. return
  27. visited[x][y] = 1
  28. cells.append((x,y))
  29. dfs(x+1,y)
  30. dfs(x,y+1)
  31. dfs(x-1,y)
  32. dfs(x,y-1)
  33.  
  34. n , m , k = get_ints()
  35. l = []
  36. for i in range(n):
  37. l.append(list(input()))
  38.  
  39. for i in range(n):
  40. for j in range(m):
  41. if not visited[i][j] and l[i][j] == '.':
  42. c = 0
  43. dfs(i,j)
  44. for x in cells:
  45. if visited[x[0]][x[1]] and out[x[0]][x[1]] == -1:
  46. out[x[0]][x[1]] = c
  47. cells.clear()
  48. for i in range(k):
  49. x , y = get_ints()
  50. x , y = x-1 , y-1
  51. ans = out[x][y]
  52. print(ans)
  53.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘import’ does not name a type
 import sys
 ^~~~~~
stdout
Standard output is empty