알고리즘/BOJ
BOJ 16469 소년점프 (Python 3)
70825
2019. 1. 21. 00:22

https://www.acmicpc.net/problem/16469
간단한 BFS 문제이다.
deque를 이용해 넉살, 스윙스, 창모의 위치를 큐에 집어 넣어준다.
R x C 배열에서 요소 하나에 3개의 값을 저장할 수 있는 다차원 배열 만들고, 넉살, 스윙스, 창모를 BFS 돌리면된다.
세 악당이 모이는데 걸리는 최소 시간은 넉살, 스윙스, 창모가 어떠한 좌표 x에서 모일 때 가장 늦게 x에 도착한 사람의 시간을 구하면 된다.
파이참 색깔 그대로 올리면 좋을텐데 아쉽게도 흰색이 전부 회색으로 나온다.
코드확인
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | from collections import deque n,m=map(int,input().split()) D=[list(map(int,[*input()])) for _ in range(n)] S=[[[-1]*3 for _ in range(m)] for _ in range(n)] q=deque() dx,dy=[0,0,1,-1],[1,-1,0,0] for i in range(3): a,b=map(int,input().split()) q.append((a-1,b-1,i)) S[a-1][b-1][i]=0 while q: x,y,z=q.popleft() for i in range(4): nx,ny=x+dx[i],y+dy[i] if 0<=nx<n and 0<=ny<m and D[nx][ny]==0 and S[nx][ny][z]==-1: q.append((nx,ny,z)) S[nx][ny][z]=S[x][y][z]+1 ans=10000 t=0 for i in range(n): for j in range(m): if min(S[i][j])!=-1: if ans>max(S[i][j]): ans=max(S[i][j]);t=1 elif max(S[i][j])==ans: t+=1 if ans==10000: print(-1) else: print(ans) print(t) | cs |