Skip to content

Commit f4aab7c

Browse files
committed
백준 14497번 주난의 난(難)
문제 링크: https://www.acmicpc.net/problem/14497
1 parent 7e54860 commit f4aab7c

File tree

1 file changed

+4
-15
lines changed
  • 백준 14497번 주난의 난(難)

1 file changed

+4
-15
lines changed

백준 14497번 주난의 난(難)/main.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,23 @@ def solve():
77
N, M = map(int, input().strip().split())
88
junan_y, junan_x, thief_y, thief_x = map(int, input().strip().split())
99
junan_y, junan_x, thief_y, thief_x = junan_y - 1, junan_x - 1, thief_y - 1, thief_x - 1
10-
maps = []
11-
12-
13-
for _ in range(N):
14-
maps.append(list(input().strip()))
15-
16-
queue = deque([[junan_y, junan_x]])
17-
18-
dys = [-1, 0, 1, 0]
19-
dxs = [0, 1, 0, -1]
20-
10+
maps = [list(input().strip()) for _ in range(N)]
2111
answer = 1
2212
students = deque()
2313

2414
while True:
2515
visited = [[False for _ in range(M)] for _ in range(N)]
2616

17+
queue = deque([[junan_y, junan_x]])
2718
while queue:
2819
sy, sx = queue.popleft()
2920
if visited[sy][sx]:
3021
continue
3122

3223
visited[sy][sx] = True
3324

34-
for i in range(len(dys)):
35-
dy, dx = dys[i], dxs[i]
25+
dyxs = [[-1, 0], [0, 1], [1, 0], [0, -1]]
26+
for dy, dx in dyxs:
3627
y, x = sy + dy, sx + dx
3728

3829
if 0 <= y < N and 0 <= x < M and visited[y][x] == False:
@@ -50,8 +41,6 @@ def solve():
5041

5142
answer += 1
5243

53-
queue.append([junan_y, junan_x])
54-
5544

5645
if __name__ == '__main__':
5746
solve()

0 commit comments

Comments
 (0)