Skip to content

Commit

Permalink
백준 14497번 주난의 난(難)
Browse files Browse the repository at this point in the history
  • Loading branch information
skysign committed Mar 2, 2025
1 parent 7e54860 commit f4aab7c
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions 백준 14497번 주난의 난(難)/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,23 @@ def solve():
N, M = map(int, input().strip().split())
junan_y, junan_x, thief_y, thief_x = map(int, input().strip().split())
junan_y, junan_x, thief_y, thief_x = junan_y - 1, junan_x - 1, thief_y - 1, thief_x - 1
maps = []


for _ in range(N):
maps.append(list(input().strip()))

queue = deque([[junan_y, junan_x]])

dys = [-1, 0, 1, 0]
dxs = [0, 1, 0, -1]

maps = [list(input().strip()) for _ in range(N)]
answer = 1
students = deque()

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

queue = deque([[junan_y, junan_x]])
while queue:
sy, sx = queue.popleft()
if visited[sy][sx]:
continue

visited[sy][sx] = True

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

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

answer += 1

queue.append([junan_y, junan_x])


if __name__ == '__main__':
solve()

0 comments on commit f4aab7c

Please sign in to comment.