λ¬Έμ
λ°±μ€ μ¨λΌμΈ μ μ§ - 13700λ²
νμ΄ κ³Όμ
μμ μ§μ μμ λͺ©ν μ§μ μ λλ¬νλ μ΅μ μ΄λ νμλ₯Ό ꡬνλ λ¬Έμ μ
λλ€.
λ¬Έμ 쑰건μμ κ²½μ°°μμ μ€κ°μ λ°©λ¬Ένλ©΄ μλλ€λ μ‘°κ±΄μ΄ μκΈ° λλ¬Έμ BFS
λ₯Ό μ΄μ©νμ¬ νμμ μ§ννκΈ° μ μ
λͺ¨λ κ²½μ°°μ μ§μ μ λ°©λ¬Έμ²λ¦¬ ν΄μ€ λ€ νμμ μννλλ‘ ν΄μ€λλ€.
μ½λ
import sys
from collections import deque
INF = 2e9
def bfs(start, goal):
q = deque()
visit = [0] * (N + 1)
q.append([start, 0])
visit[start] = 1
for office in police_office:
visit[office] = 1
while q:
here, click = q.popleft()
if here == goal:
return click
for there in [here + F, here - B]:
if 1 <= there <= N and not visit[there]:
visit[there] = 1
q.append([there, click + 1])
return INF
def solution():
press_count = bfs(S, D)
return press_count if press_count != INF else 'BUG FOUND'
if __name__ == '__main__':
N, S, D, F, B, K = list(map(int, sys.stdin.readline().split()))
police_office = list(map(int, sys.stdin.readline().split()))
answer = solution()
print(answer)
λ°μν
'π algorithm > boj' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
BOJ 5076 - Web Pages (0) | 2021.07.19 |
---|---|
BOJ 1920 - μ μ°ΎκΈ° (0) | 2021.07.05 |
BOJ 14950 - μ 볡μ (0) | 2021.06.25 |
BOJ 1197 - μ΅μ μ€ν¨λ νΈλ¦¬ (0) | 2021.06.18 |
BOJ 4963 - μ¬μ κ°μ (0) | 2021.06.15 |
π¬ λκΈ