본문 바로가기

Algorithm/BOJ133

[백준] 7662번 - 이중 우선순위 큐 (파이썬) # 이중 우선순위 큐 import heapq T = int(input()) for _ in range(T): N = int(input()) min_heap = [] max_heap = [] visited = [False] * N for idx in range(N): order, data = input().split() data = int(data) if order == 'I': heapq.heappush(min_heap, (data, idx)) heapq.heappush(max_heap, (-data, idx)) visited[idx] = True elif order == 'D': if data == 1: while max_heap and not visited[max_heap[0][1]]: heapq.h.. 2022. 5. 17.
[백준] 2109번 - 순회강연 (파이썬) # 순회강연 import sys input = sys.stdin.readline N = int(input()) info = [] max_day = 0 for _ in range(N): pay, day = map(int, input().split()) max_day = max(max_day, day) info.append((day, pay)) info.sort(key=lambda i: (i[1], i[0])) possible = [True for i in range(max_day+1)] result = 0 for _ in range(N): day, pay = info.pop() for d in range(day, 0, -1): if possible[d]: possible[d] = False result +.. 2022. 5. 15.
[백준] 19238번 - 스타트 택시 (파이썬) # 스타트 택시 from collections import deque import sys input = sys.stdin.readline N, M, fuel = map(int, input().split()) # 지도 arr = [[]] for _ in range(N): arr.append([0]+list(map(int, input().split()))) # 현재 위치 taxi = list(map(int, input().split())) # 사람들 정보 people = [] for _ in range(M): people.append(list(map(int, input().split()))) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def find_person(): tx, ty =.. 2022. 5. 14.
[백준] 8980번 - 택배 (파이썬) # 택배 import sys input = sys.stdin.readline N, W = map(int, input().split()) box_num = int(input()) box_info = [] for _ in range(box_num): start, end, num = map(int, input().split()) box_info.append((start, end, num)) box_info.sort(key=lambda x: (x[1])) result = 0 arr = [W for _ in range(N+1)] for x, y, num in box_info: num = min(num, min(arr[x:y])) if num != 0: for i in range(x, y): arr[i] -= nu.. 2022. 5. 13.
[백준] 1039번 - 교환 (파이썬) # 교환 from collections import deque N, K = map(int, input().split()) M = len(str(N)) def bfs(N, K): visited = set() visited.add((N, 0)) q = deque() q.append((N, 0)) answer = 0 while q: n, k = q.popleft() if k == K: answer = max(answer, n) continue n = list(str(n)) for i in range(M-1): for j in range(i+1, M): if i == 0 and n[j] == '0': continue n[i], n[j] = n[j], n[i] nn = int(''.join(n)) if (nn, .. 2022. 5. 4.
[백준] 15961번 - 회전 초밥 # 회전 초밥 from collections import defaultdict N, d, k, c = map(int, input().split()) arr = [int(input()) for _ in range(N)] arr += arr[:k-1] left, right = 0, k result = 0 dict = defaultdict(int) dict[c] += 1 for x in arr[left:right]: dict[x] += 1 while right < len(arr): result = max(result, len(dict)) dict[arr[left]] -= 1 dict[arr[right]] += 1 if dict[arr[left]] == 0: dict.pop(arr[left]) left += 1.. 2022. 5. 3.
[백준] 1507번 - 궁금한 민호 (파이썬) # 궁금한 민호 N = int(input()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) road = [[True]*N for _ in range(N)] # 플로이드 와샬 역으로 result = 0 for k in range(N): for i in range(N): if i != k: for j in range(N): if i != j and k != j: if arr[i][j] == arr[i][k]+arr[k][j]: road[i][j] = False elif arr[i][j] > arr[i][k]+arr[k][j]: result = -1 if not result: for i in range(N): for j in .. 2022. 5. 2.