ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

16956๋ฒˆ: ๋Š‘๋Œ€์™€ ์–‘

ํฌ๊ธฐ๊ฐ€ R×C์ธ ๋ชฉ์žฅ์ด ์žˆ๊ณ , ๋ชฉ์žฅ์€ 1×1 ํฌ๊ธฐ์˜ ์นธ์œผ๋กœ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ๋‹ค. ๊ฐ๊ฐ์˜ ์นธ์—๋Š” ๋น„์–ด์žˆ๊ฑฐ๋‚˜, ์–‘ ๋˜๋Š” ๋Š‘๋Œ€๊ฐ€ ์žˆ๋‹ค. ์–‘์€ ์ด๋™ํ•˜์ง€ ์•Š๊ณ  ์œ„์น˜๋ฅผ ์ง€ํ‚ค๊ณ  ์žˆ๊ณ , ๋Š‘๋Œ€๋Š” ์ธ์ ‘ํ•œ ์นธ์„ ์ž์œ ๋กญ๊ฒŒ ๏ฟฝ

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ํฌ๊ธฐ๊ฐ€ RxC์ธ ๋ชฉ์žฅ์ด ์žˆ๊ณ , ์–‘๊ณผ ๋Š‘๋Œ€๊ฐ€ ๋ชฉ์žฅ ์•ˆ์— ์žˆ๋‹ค. ์šธํƒ€๋ฆฌ๋ฅผ ์„ค์น˜ํ•˜์—ฌ ๋Š‘๋Œ€๊ฐ€ ์–‘์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†์œผ๋ฉด 1์„ ์ถœ๋ ฅํ•˜๊ณ , ์•„๋‹Œ ๊ฒฝ์šฐ 0์„ ์ถœ๋ ฅํ•œ๋‹ค. ๋Š‘๋Œ€๊ฐ€ ์–‘์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ๋Š” ๋Š‘๋Œ€์™€ ์–‘์ด ์ธ์ ‘ํ•ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ์ด๋‹ค. ๋ฌธ์ œ์—์„œ ์ตœ์†Œ ์šธํƒ€๋ฆฌ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ, ๋Š‘๋Œ€๊ฐ€ ์–‘์— ์ ‘๊ทผํ•˜์ง€ ๋ชปํ•˜๋„๋ก ๋ง‰์œผ๋ฉด ๋˜๋ฏ€๋กœ ์–‘์„ ๊ธฐ์ค€์œผ๋กœ `์ƒ, ํ•˜, ์ขŒ, ์šฐ`๋กœ ์šธํƒ€๋ฆฌ๋ฅผ ์„ค์น˜ํ•˜๋ฉด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin


def visitable(x, y):
    return 0 <= x < r and 0 <= y < c


def solve():
    dirs = ((0, -1), (0, 1), (-1, 0), (1, 0))

    for x in range(r):
        for y in range(c):
            # ์–‘์ธ ๊ฒฝ์šฐ
            if graph[x][y] == 'S':
                # ์–‘์˜ 4๋ฐฉํ–ฅ์œผ๋กœ ํƒ์ƒ‰ํ•˜์—ฌ, ๋Š‘๋Œ€๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ
                for dx, dy in dirs:
                    next_x, next_y = x + dx, y + dy

                    if visitable(next_x, next_y):
                        if graph[next_x][next_y] == 'W':
                            return 0
                        elif graph[next_x][next_y] == '.':
                            graph[next_x][next_y] = 'D'
            else:
                continue
    return 1


if __name__ == '__main__':
    r, c = map(int, stdin.readline().split())
    graph = [list(stdin.readline().rstrip()) for _ in range(r)]

    if solve():
        print(1)
        for row in graph:
            print(''.join(row))
    else:
        print(0)

 

 

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€