Skip to content

Commit e34e97e

Browse files
committed
solve(BOJ): G5_14503_로봇 청소기_py
1 parent 9c00c3c commit e34e97e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/boj/G5_14503_로봇_청소기.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# https://www.acmicpc.net/problem/14503
2+
# 3:31~4:10
3+
4+
from collections import deque
5+
6+
7+
def solution():
8+
n, m = map(int, input().split())
9+
r, c, d = map(int, input().split())
10+
board = [list(map(int, input().split())) for _ in range(n)]
11+
12+
ds = ((-1, 0), (0, 1), (1, 0), (0, -1))
13+
s = deque([(r, c)])
14+
count = 0
15+
while len(s) > 0:
16+
x, y = s.pop()
17+
if board[x][y] == 0:
18+
board[x][y] = 2
19+
count += 1
20+
21+
is_all_clean = True
22+
for dx, dy in ds:
23+
nx = x + dx
24+
ny = y + dy
25+
if 0 <= nx < n and 0 <= ny < m and board[nx][ny] == 0:
26+
is_all_clean = False
27+
d = (d + 3) % 4
28+
break
29+
30+
if not is_all_clean:
31+
nx = x + ds[d][0]
32+
ny = y + ds[d][1]
33+
if 0 <= nx < n and 0 <= ny < m and board[nx][ny] == 0:
34+
s.append((nx, ny))
35+
else:
36+
s.append((x, y))
37+
else:
38+
nx = x - ds[d][0]
39+
ny = y - ds[d][1]
40+
if 0 <= nx < n and 0 <= ny < m and board[nx][ny] != 1:
41+
s.append((nx, ny))
42+
else:
43+
break
44+
45+
return count
46+
47+
48+
print(solution())

0 commit comments

Comments
 (0)