728x90
삼성 SW 역량 테스트 기출 문제인 14503번 문제
문제를 그대로 코드로 구현하면 되는 직관적인 문제였다.
def clean(now_row, now_col, direction):
if li[now_row][now_col] == 0:
li[now_row][now_col] = 2 #2는 청소된 부분을 말한다
if li[now_row][now_col - 1] != 0 and li[now_row - 1][now_col] != 0 and li[now_row][now_col + 1] != 0 and li[now_row + 1][now_col] != 0:
if direction == 0 and li[now_row + 1][now_col] != 1:
clean(now_row + 1, now_col, direction)
elif direction == 1 and li[now_row][now_col - 1] != 1:
clean(now_row, now_col - 1, direction)
elif direction == 2 and li[now_row - 1][now_col] != 1:
clean(now_row - 1, now_col, direction)
elif direction == 3 and li[now_row][now_col + 1] != 1:
clean(now_row, now_col + 1, direction)
else:
return
elif direction == 0:
if li[now_row][now_col - 1] == 0:
clean(now_row, now_col - 1, 3)
else:
clean(now_row, now_col, 3)
elif direction == 1:
if li[now_row - 1][now_col] == 0:
clean(now_row - 1, now_col, 0)
else:
clean(now_row, now_col, 0)
elif direction == 2:
if li[now_row][now_col + 1] == 0:
clean(now_row, now_col + 1, 1)
else:
clean(now_row, now_col, 1)
elif direction == 3:
if li[now_row + 1][now_col] == 0:
clean(now_row + 1, now_col, 2)
else:
clean(now_row, now_col, 2)
from sys import stdin
n, m = list(map(int, stdin.readline().split()))
r, c, d = list(map(int, stdin.readline().split()))
li = []
visited = [[False] * m for i in range(n)]
for i in range(n):
li.append(list(map(int, stdin.readline().split())))
clean(r, c, d)
count = 0
for i in range(n):
for j in range(m):
if li[i][j] == 2:
count += 1
print(count)
728x90
'알고리즘 문제' 카테고리의 다른 글
[백준] 1932번 정수 삼각형 (0) | 2020.01.18 |
---|---|
[백준] 14890번 경사로 (0) | 2020.01.16 |
[백준] 1149번 RGB 거리 (0) | 2020.01.12 |
[백준] 9461번 파도반수열 (0) | 2020.01.12 |
[백준] 11729번 하노이 탑 이동 순서 (0) | 2020.01.12 |