[백준 4991번] 로봇 청소기 (Python3)
import sys input = sys.stdin.readline from collections import deque dy = [1,-1,0,0] dx = [0,0,1,-1] INF = 10**6 def BFS(y,x,n): visited = [[0]*M for i in range(N)] dq = deque() dq.append((y,x,0)) while dq: y,x,d = dq.popleft() if visited[y][x]: continue visited[y][x] = 1 if room[y][x] == "*": n1 = numdict[(y,x)] graph[n][n1] = graph[n1][n] = d for i in range(4): y1,x1 = y+dy[i],x+dx[i] if N>y1>=..
[백준 18809번] Gaaaaaaaaaarden (Python3)
import sys input = sys.stdin.readline from itertools import combinations from collections import deque dy = [1,-1,0,0] dx = [0,0,1,-1] def BFS(): flower = 0 while dq: y,x,ylast,xlast,time,color = dq.popleft() if visited[ylast][xlast] == 1: #전에 꽃이 폈으면 continue if visited[y][x]: if visited[y][x] == (time,-color): visited[y][x] = 1 flower += 1 continue visited[y][x] = (time,color) for i in range(4)..
[백준 1486번] 등산 (Python3)
import sys input = sys.stdin.readline from heapq import heappush,heappop INF = sys.maxsize dy = [1,-1,0,0] dx = [0,0,1,-1] def Djikstra(x): DP = [INF]*N*M hq = [] heappush(hq,(0,x)) while hq: w,now = heappop(hq) if DP[now] y1>=0 and M>x1>=0: h1 = MAP[y1][x1] if abs(h-h1) h: d = (h1-h)**2 graph[y*M+x].append((y1*M+x1,d)) DP = [INF]*N*M hq = [] heappush(hq,(0,0)) while hq: w,now = heappop(hq) if D..
[백준 19236번] 청소년 상어 (Python3)
import sys input = sys.stdin.readline from copy import deepcopy dy = [-1,-1,0,1,1,1,0,-1] dx = [0,-1,-1,-1,0,1,1,1] def movefish(n,ocean): y,x = where[n] d = ocean[y][x][1] for i in range(8): y1,x1 = y+dy[(i+d)%8],x+dx[(i+d)%8] if 4>y1>=0 and 4>x1>=0: if ocean[y1][x1]: if ocean[y1][x1][0] == -1: continue ocean[y][x] = ocean[y1][x1] where[ocean[y][x][0]] = (y,x) else: ocean[y][x] = 0 ocean[y1][x1..