Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fin = open('input.txt', 'r')
- fout = open('output.txt', 'w')
- n, m = map(int, fin.readline().rstrip().split())
- A = []
- Q = []
- x0, y0 = map(int, fin.readline().rstrip().split())
- New_color = int(fin.readline().rstrip())
- for i in range(n):
- A.append(list(map(int, fin.readline().rstrip().split())))
- color = A[y0][x0]
- Q.append((y0, x0))
- count = 0
- if A[y0][x0] != New_color:
- while len(Q) != 0:
- y, x = Q.pop(0)
- if A[y][x] == color:
- count += 1
- A[y][x] = New_color
- if x > 0:
- Q.append((y, x - 1))
- if x < m - 1:
- Q.append((y, x + 1))
- if y > 0:
- Q.append((y - 1, x))
- if y < n - 1:
- Q.append((y + 1, x))
- fout.write(str(count) + '\n')
- for i in range(n):
- fout.write(' '.join(list(map(str, A[i]))) + '\n')
- fin.close()
- fout.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement