알고리즘(48)
-
[백준] 15685번: 드래곤 커브 (Python3)
보호되어 있는 글입니다.
2024.04.26 -
[Softeer] [한양대 HCPC 2023] X marks the Spot (Python)
import sys input = sys.stdin.readline N = int(input()) answer = [] for _ in range(N): S, T = map(str, input().split()) for i, s in enumerate(S): if s == 'x' or s == 'X': answer.append(T[i].upper()) break print(''.join(answer))
2024.03.22 -
[백준] 14503번 : 로봇청소기 (Python3)
from collections import deque N, M = map(int, input().split()) r, c, d = map(int, input().split()) rooms = [list(map(int, input().split())) for _ in range(N)] visited = [[False] * M for _ in range(N)] dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] cnt = 0 def bfs(x, y, d): global cnt q = deque() q.append((x, y)) visited[x][y] = True cnt += 1 while q: x, y = q.popleft() turn = 0 for i in range(4): d = (d ..
2024.03.19 -
[LeetCode] Keys and Rooms (Python)
보호되어 있는 글입니다.
2024.03.09 -
[LeetCods] 01Matrix (Python)
from collections import deque class Solution: def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]: row, col = len(mat), len(mat[0]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] INF = 1e9 q = deque() for i in range(row): for j in range(col): if mat[i][j] == 0: q.append((i, j)) else : mat[i][j] = INF while q: x, y = q.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] z = mat[x][y] + ..
2024.03.09 -
[LeetCode] Flood Fill (Python)
from collections import deque class Solution: def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]: before = image[sr][sc] row, col = len(image), len(image[0]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] if before != color: q = deque() q.append([sr, sc]) while q: x, y = q.popleft() image[x][y] = color for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0
2024.03.09