얼렁뚱땅 백준 문제풀이
[백준 문제풀이] 얼렁뚱땅 14503 로봇청소기 풀이
MOSTAR
2022. 9. 17. 20:23
https://www.acmicpc.net/problem/14503
14503번: 로봇 청소기
로봇 청소기가 주어졌을 때, 청소하는 영역의 개수를 구하는 프로그램을 작성하시오. 로봇 청소기가 있는 장소는 N×M 크기의 직사각형으로 나타낼 수 있으며, 1×1크기의 정사각형 칸으로 나누어
www.acmicpc.net
벽과 청소한 곳을 분리해줘야 하는데, 이걸 분리 안해줘서 다풀고 오래걸렸다 ..
(분리 안해도 테케는 맞음)
왜냐면, 4방향 모두 청소가 되어있으면 뒤로 한칸 가는 것이 있는데, 벽이면 뒤로 못가서 break해야하고
청소가 된 곳이면 상관 없이 그냥 뒤로 갈 수 있기 때문이다
ㅡ3ㅡ..
n, m = map(int,input().split())
r, c, d = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(n)]
count = 0
check_turn = 0
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
while True :
if arr[r][c] == 0 :
arr[r][c] = 2
count += 1
check_turn = 0
sign = 0
for _ in range(4) :
check_turn += 1
d = d-1
if d == -1 :
d = 3
nx = r + dx[d]
ny = c + dy[d]
if 0<=nx<n and 0<=ny<m :
if arr[nx][ny] == 0 :
sign = 1
r = nx
c = ny
break
if sign == 0 :
nx = r - dx[d]
ny = c - dy[d]
if 0<=nx<n and 0<=ny<m :
if arr[nx][ny] == 1:
break
r = nx
c = ny
else :
break
print(count)