[백준] 16956번 : 늑대와 양 - Python(파이썬)

강재원·2022년 11월 24일
0

[코딩테스트] Python

목록 보기
187/200
post-custom-banner



https://www.acmicpc.net/problem/16956

r,c=map(int,input().split())
arr=[[0 for _ in range(c)] for _ in range(r)]
for i in range(r):
    st=input()
    for j in range(c):
        arr[i][j]=st[j]

check=True
dx=[0,0,1,-1]
dy=[1,-1,0,0]

for i in range(r):
    for j in range(c):
        if arr[i][j]=='W':
            for k in range(4):
                x=i+dx[k]
                y=j+dy[k]

                if x>=0 and x<r and y>=0 and y<c:
                    if arr[x][y]=='.':
                        arr[x][y]='D'
                    elif arr[x][y]=='S':
                        check=False
                        print(0)
                        exit()

if check==False: print(0)
else:
    print(1)
    for i in range(r):
        for j in range(c):
            print(arr[i][j],end='')
        print()
profile
개념정리 & 문법 정리 & 알고리즘 공부
post-custom-banner

0개의 댓글