목차

늑대와 양

ps
링크acmicpc.net/…
출처BOJ
문제 번호16956
문제명늑대와 양
레벨실버 3
분류

애드혹

시간복잡도O(n*m)
인풋사이즈n<=500, m<=500
사용한 언어Python
제출기록31084KB / 96ms
최고기록80ms
해결날짜2022/09/22

풀이

코드

"""Solution code for "BOJ 16956. 늑대와 양".

- Problem link: https://www.acmicpc.net/problem/16956
- Solution link: http://www.teferi.net/ps/problems/boj/16956

Tags: [Ad hoc]
"""

def main():
    R, C = [int(x) for x in input().split()]  # pylint: disable=unused-variable
    board = [input() for _ in range(R)]

    for row in board:
        if 'SW' in row or 'WS' in row:
            print('0')
            return
    for col in zip(*board):
        col = ''.join(col)
        if 'SW' in col or 'WS' in col:
            print('0')
            return

    print('1')
    print('\n'.join(row.replace('.', 'D') for row in board))


if __name__ == '__main__':
    main()