[백준]230403-09 문제풀이(Python)
9328. 열쇠 from collections import deque import sys input = sys.stdin.readline dy = [-1, 1, 0, 0] dx = [0, 0, -1, 1] def bfs(y, x): global ans q = deque() q.append((y, x)) visited = [[False] * (w + 2) for _ in range(h + 2)] visited[y][x] = True while q: cnt = 0 now = q.popleft() for d in range(4): ny, nx = now[0] + dy[d], now[1] + dx[d] if ny h + 1 or nx w + 1: continue if ..
2023. 4. 9.
[백준]230303-05 문제풀이
19237. 어른 상어 import sys input = sys.stdin.readline dy = [0, -1, 1, 0, 0] dx = [0, 0, 0, -1, 1] def move(i, j): n = lst[i][j] for d in range(1, 5): yy = i + dy[D[n][now_D[n]][d]] xx = j + dx[D[n][now_D[n]][d]] if yy not in range(N) or xx not in range(N): continue if not smell[yy][xx]: now_D[n] = D[n][now_D[n]][d] return yy, xx for d in range(1, 5): yy = i + dy[D[n][now_D[n]][d]] xx = j + dx[D[n][..
2023. 3. 6.
[백준]230228-0301 문제풀이
7569. 토마토 from collections import deque import sys input = sys.stdin.readline dz = [0, 0, 0, 0, -1, 1] dy = [-1, 1, 0, 0, 0, 0] dx = [0, 0, -1, 1, 0, 0] def bfs(): global ripe day = 0 while queue: qpop = queue.popleft() a, b, c, day = qpop[0], qpop[1], qpop[2], qpop[3] visited[a][b][c] = True for d in range(6): if a + dz[d] in range(H) and b + dy[d] in range(N) and c + dx[d] in range(M): if toma..
2023. 3. 1.
[백준]230223-24 문제풀이
1405. 미친 로봇 dy = [0, 0, 1, -1] dx = [1, -1, 0, 0] n, E, W, S, N = map(int, input().split()) dirs = [E, W, S, N] def dfs(y, x, direction, visited, cnt): global percentage if (y, x) in visited: temp = 1 for i in direction: temp *= dirs[i] / 100 percentage -= temp return if cnt == n: return for d in range(4): dfs(y + dy[d], x + dx[d], direction + [d], visited + [(y, x)], cnt + 1) percentage = 1 dfs..
2023. 2. 24.
[백준]230214 문제풀이
2638. 치즈 from collections import deque N, M = map(int, input().split()) lst = [] dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] time = 0 for i in range(N): a = list(map(int, input().split())) lst.append(a) while True: cheeze = deque([]) # 공기부분 -1로 변환 lst[0][0] = -1 queue = deque([(0, 0)]) visited = [[False] * M for _ in range(N)] while queue: a = queue.pop() visited[a[0]][a[1]] = True temp = [] for k in ..
2023. 2. 14.