본문 바로가기

분류 전체보기318

[백준/파이썬] #20444 문제를 보고 한 번 자를 때마다 모든 케이스를 다 탐색하는, 지수 함수 복잡도의 경우밖에는 생각나지 않아서 풀이를 참고했다. 정말 간결하고 직관적인 풀이였다. def divide(): left, right = 0, N // 2 while left pieces: left = row_cut + 1 else: right = row_cut - 1 return Falseif __name__ == "__main__": N, K = map(int, input().split()) print("YES") if divide() else print("NO") 2025. 5. 26.
20250525 회고 보호되어 있는 글 입니다. 2025. 5. 25.
[백준/파이썬] #13023 40분 정도 걸렸는데, 결국 풀이를 안 보고 잘 맞췄다. 처음에는 A, B, C, D, E를 찾는 게 아니라 이런 방식으로 모든 노드가 연결되어야 한다고 착각했다. 문제 요건을 잘 읽어보자. from collections import defaultdictdef dfs(node, depth): global answer global visited if depth >= 4: answer = True return for next_node in graph[node]: if not visited[next_node]: visited[next_node] = True dfs(next_node, depth + 1) .. 2025. 5. 25.
[백준/파이썬] #17836 오랜만에 답을 안 보고 30분 안에 풀었다. BFS와 heap을 사용해서 풀었다. import heapqINF = 1e9dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]def direct_path(end_x, end_y): start_x, start_y = 0, 0 visited = [[False] * M for _ in range(N)] visited[start_x][start_y] = True heap = [] heapq.heappush(heap, (0, start_x, start_y)) while heap: dist, cur_x, cur_y = heapq.heappop(heap) if cur_x == end_x and cur_.. 2025. 5. 20.
20250518 회고 보호되어 있는 글 입니다. 2025. 5. 18.
[백준/파이썬] #2469 약 30분간 시도했는데, 하나의 함수 구현방법이 떠오르지 않아서(정확히는 좀 까다로워 보여서) 시간을 넘겼다. def proceed(): current_position = [chr(i+65) for i in range(K)] next_position = [None] * K for i in range(len(before_ladder)): next_position = current_position string = before_ladder[i] for j in range(K-2): if j == 0: if string[j] == "-": next_position[j+1] = c.. 2025. 5. 18.