-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path948A.py
More file actions
34 lines (26 loc) · 775 Bytes
/
948A.py
File metadata and controls
34 lines (26 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# @author Matheus Alves dos Santos
def is_sheep_safe(i, j):
if ((i > 0) and (pasture[i - 1][j] == 'W')):
return False
if ((i < rows - 1) and (pasture[i + 1][j] == 'W')):
return False
if ((j > 0) and (pasture[i][j - 1] == 'W')):
return False
if ((j < columns - 1) and (pasture[i][j + 1] == 'W')):
return False
return True
rows, columns = map(int, input().split())
pasture = []
possible = True
for i in range(rows):
pasture.append(input().replace('.', 'D'))
for i in range(rows):
for j in range(columns):
if ((pasture[i][j] == 'S') and not is_sheep_safe(i, j)):
possible = False
if (possible):
print('Yes')
for i in pasture:
print(i)
else:
print('No')