목록백준 (60)
컴공생의 다이어리
백준 2225번 : 합분해 (문제 바로가기) 내 코드 n, k = map(int, input().split()) dp = [[0] * (k + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(n + 1): for j in range(1, k + 1): dp[i][j] = dp[i - 1][j] + dp[i][j - 1] print(dp[n][k] % 1000000000)
백준 14676번 : 영우는 사기꾼? (문제 바로가기) 내 코드 import sys from collections import defaultdict input = sys.stdin.readline # n : 건물 종류의 개수, M : 건물 사이의 관계수, k : 영우의 게임 정보의 개수 n, m, k = map(int, input().split()) graph = defaultdict(list) # 건물 관계 indegree = [0] * (n + 1) # 진입 차수 build = [0] * (n + 1) # 빌딩 몇개 지어졌는지 check = False # 치트키 여부 for _ in range(m): # 건물 관계 x, y = map(int, input().split()) graph[x].append..
백준 1474번 : 밑 줄 (문제 바로가기) 내 코드 import sys input = sys.stdin.readline n, m = map(int, input().split()) data = [input().rstrip() for _ in range(n)] default_len, r = divmod(m - sum(map(len, data)), n - 1) result = data[0] for idx in range(1, n): if data[idx][0].islower() and r != 0: r -= 1 result += '_' * (default_len + 1) + data[idx] elif idx + r == n: r -= 1 result += '_' * (default_len + 1) + dat..
백준 1005번 : ACM Craft (문제 바로가기) 내 코드 import sys from collections import defaultdict, deque input = sys.stdin.readline for _ in range(int(input())): n, k = map(int, input().split()) times = list(map(int, input().split())) result = times[::] indegree = [0] * n arr = defaultdict(list) for _ in range(k): a, b = map(int, input().split()) arr[a - 1].append(b - 1) indegree[b - 1] += 1 w = int(input()) -..
백준 1715번 : 카드 정렬하기 (문제 바로가기) 내 코드 import heapq import sys input = sys.stdin.readline n = int(input()) card = [int(input()) for _ in range(n)] heapq.heapify(card) result = 0 while len(card) > 1: a, b = heapq.heappop(card), heapq.heappop(card) result += a + b heapq.heappush(card, a + b) print(result)
백준 1717번 : 집합의 표현 (문제 바로가기) 내 코드 import sys sys.setrecursionlimit(10**8) def find_parent(parent, x): if parent[x] != x: parent[x] = find_parent(parent, parent[x]) return parent[x] def union(parent, a, b): a = find_parent(parent, a) b = find_parent(parent, b) if a < b: parent[b] = a else: parent[a] = b input = sys.stdin.readline n, m = map(int, input().split()) parent = [i for i in range(n + 1)] ..
백준 11286번 : 절댓값 힙 (문제 바로가기) 내 코드 import heapq, sys n = int(input()) heap = [] for _ in range(n): num = int(sys.stdin.readline()) if num == 0: if heap: print(heapq.heappop(heap)[1]) else: print(0) else: heapq.heappush(heap, (abs(num), num))
백준 2178번 : 미로 탐색 (문제 바로가기) 내 코드 import sys from collections import deque, defaultdict input = sys.stdin.readline def bfs(graph, start, n, m): # graph : 미로 정보 # start : 시작 좌표 d = [(0, 1), (0, -1), (1, 0), (-1, 0)] # 상하좌우 방향 visited = defaultdict(int) # 좌표별 최소 이동 거리 저장 용 queue = deque([start]) visited[start] = 1 while queue: x, y = queue.popleft() # 현재 좌표 if graph[x][y] == 1: # 이동할 수 있는 칸인가? for x..
백준 2075번 : N번째 큰 수 (문제 바로가기) 내 코드 import sys, heapq input = sys.stdin.readline heap = [] for _ in range(int(input())): arr = list(map(int, input().split())) if not heap: for a in arr: heapq.heappush(heap, a) else: for a in arr: if heap[0] < a: heapq.heappush(heap, a) heapq.heappop(heap) print(heap[0])
백준 1012번 : 유기농 배추 (문제 바로가기) 내 코드 import sys sys.setrecursionlimit(10**6) def dfs(x, y): visited[x][y] = True directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] for dx, dy in directions: nx, ny = x + dx, y + dy if nx = n or ny = m: continue if array[nx][ny] and not visited[nx][ny]: dfs(nx, ny) for _ in range(int(input())): m, n, k = map(int, input().split()) array = [[0] * m fo..