백준

2109번 – 순회강연

2

문제 풀이 코드 n = int(input()) pds = [] maxD = 0 for _ in range(n): p, d = map(int ,input().split()) pds.append((p, d)) maxD = max(maxD, d) def answer(): global pds, maxD pds = sorted(pds, reverse=True) memo = [0]*(maxD+1) count, fullCount = (0, len(memo)) for i in range(len(pds)): p, d = pds[i] if memo[d] == 0: memo[d] = p count += 1 else: for underD in range(d-1, 0, -1): if memo[underD] == 0:...

11066번 – 파일합치기

1

문제 풀이 코드 재귀로 풀기 from sys import stdin costs = [] minSums = [] arr = [] big = 10**8+1 def 최소합찾기(s, e): global arr, minSums if minSums[s][e] > 0: return minSums[s][e] if s == e: return 0 minSum = big for i in range(s, e): ls, le, rs, re = s, i, i+1, e minSums[ls][le], minSums[rs][re] = 최소합찾기(ls, le), 최소합찾기(rs, re) 후보 = minSums[ls][le]+minSums[rs][re]+(costs[re]) if ls > 0: 후보 -= costs[ls-1]...

1939번 – 중량제한

1

문제 풀이 코드 from sys import stdin from collections import deque n, m = map(int, input().split()) graph = {} ws = [] for _ in range(m): a, b, c = map(int, stdin.readline().split()) if graph.get(a) is None: graph[a] = [(b, c)] else: graph[a].append((b, c)) if graph.get(b) is None: graph[b] = [(a, c)] else: graph[b].append((a, c)) ws.append(c) S, E = map(int, input().split()) ws = sorted(ws) def...

1780번 – 종이의 개수

1

문제 풀이 코드 n = int(input()) B = [list(map(int, input().split())) for _ in range(n)] def answer(): global board counts = [0, 0, 0] boards = [B] while(len(boards) > 0): board = boards.pop() num, result = 모두같은숫자인지체크(board) if result is True: counts[num] += 1 elif (len(board) >= 3): boards.extend(종이자르기(board)) print(counts[-1]) print(counts[0]) print(counts[1]) def 종이자르기(board): s1, s2 =...

1495번 – 기타리스트

1

문제 풀이 코드 from collections import deque n, s, m = map(int, input().split()) diffs = list(map(int, input().split())) visited = [[False]*101 for _ in range(1001)] candidates = [-1] def answer(): global candidates DP() return max(candidates) def DP(): global n, s, m, diffs, candidates, visited Q = deque([(s, 0)]) while(len(Q) > 0): volum, i = Q.popleft() if i >= len(diffs): candidates.append(volum)...

19584번 – 난개발

1

문제 풀이 코드 from sys import stdin n, m = map(int, input().split()) 주요장소들 = [0]+[list(map(int, stdin.readline().split())) for _ in range(n)] line = [] for _ in range(m): ai, bi, 통행량 = map(int, stdin.readline().split()) (ax, ay), (bx, by) = 주요장소들[ai], 주요장소들[bi] if ay > by: line.extend([(ay, 통행량), (by-1, -1*통행량)]) else: line.extend([(by, 통행량), (ay-1, -1*통행량)]) line = sorted(line, key = lambda x: (...

7576번 – 토마토

7

문제 풀이 코드 from collections import deque from copy import deepcopy m, n = map(int, input().split()) board = [list(map(int, input().split())) for _ in range(n)] board = [[-1]*m] + board + [[-1]*m] for y in range(len(board)): board[y] = [-1] + board[y] + [-1] dyx = [(-1, 0), (0, 1), (1, 0), (0, -1)] def answer(): global m, n, board day = BFS() # 다 익었어야 했는데, 안익었다면... if 토마토가다익었나(board) is False:...