알고리즘 문제풀이 (185) 썸네일형 리스트형 저울 [백준 10159] https://www.acmicpc.net/problem/10159 from collections import deque n = int(input())m = int(input())gra = [[] for _ in range(n+1)] for _ in range(m): a,b = map(int, input().split()) gra[a].append((b,1))# a>b weight gra[b].append((a,-1))counts = [0]*(n+1) def find(start): # visi q = deque() q.append((start,0)) while q : now,nowway= q.popleft() for nextnode,wa.. 친구비 [백준 16562] https://www.acmicpc.net/problem/16562 from collections import deque n, m, k = map(int ,input().split())arr = [0] + list(map(int, input().split()))gra = [[] for _ in range(n+1)] for _ in range(m): a, b = map(int, input().split()) if a != b: gra[a].append(b) gra[b].append(a) visit = [0 for _ in range(n+1)]def bfs(start): q = deque() q.append(start) visit[start].. 게임 [백준 1072] https://www.acmicpc.net/problem/1072 def check(x, y): z = (y * 100) // x if z >= 99: return -1 left, right = 1, 1_000_000_000 answer = -1 while left z: answer = mid right = mid - 1 else: left = mid + 1 return answer# 입력 처리x, y = map(int, input().split())print(check(x, y)) House Prices Going Up [백준 25778] https://www.acmicpc.net/problem/25778 무엇이 틀린지 몰라 gpt에 물어보니 long long을 써야함을 알게됨 #include #include using namespace std;int n;vector arr, tree;long long init(int idx, int s, int e) { if (s == e) { tree[idx] = arr[s]; return tree[idx]; } int mid = s + (e - s) / 2; tree[idx] = init(idx * 2, s, mid) + init(idx * 2 + 1, mid + 1, e); return tree[idx];}void update(int idx, in.. 풍선 맞추기 [백준 11509] https://www.acmicpc.net/problem/11509 import sysinput = sys.stdin.readlinen = int(input())balloons = list(map(int, input().split()))arrows = {}arrow_count = 0for height in balloons: if height in arrows and arrows[height] > 0: arrows[height] -= 1 arrows[height - 1] = arrows.get(height - 1, 0) + 1 else: arrow_count += 1 arrows[height - 1] = arrows.get(height - 1, .. 연료 채우기 [백준 1826] https://www.acmicpc.net/problem/1826 import heapqimport sys# input = sys.stdin.read# data = input().splitlines()N = int(input()) # 주유소 개수stations = []for i in range(1, N + 1): # a, b = map(int, data[i].split()) a, b = map(int, input().split()) stations.append((a, b))L, P = map(int, input().split()) # 마을까지 거리, 현재 연료stations.sort()max_heap = []fuel = Pcount = 0index = 0 while fuel 파일 합치기3 [백준 13975] https://www.acmicpc.net/problem/13975 import heapqt = int(input()) # 테스트 케이스 수for _ in range(t): k = int(input()) # 배열의 길이 arr = list(map(int, input().split())) heapq.heapify(arr) total = 0 while len(arr) > 1: a1 = heapq.heappop(arr) a2 = heapq.heappop(arr) total += (a1 + a2) heapq.heappush(arr, (a1 + a2)) print(total) 멀티탭 스케줄링 [백준 1700] https://www.acmicpc.net/problem/1700 # 입력 받기n, k = map(int, input().split()) # n: 멀티탭 구멍 수, k: 사용 순서 길이order = list(map(int, input().split()))multitap = []swap_count = 0for i in range(k ): curr = order[i] for i in range(k): current = order[i] if current in multitap: continue if len(multitap) farthest: farthest = next_use index_to_remove = j multitap[.. 이전 1 2 3 4 ··· 24 다음