[백준] 16562번 - 친구비 (파이썬)
# 친구비 import sys import heapq input = sys.stdin.readline N, M, k = map(int, input().split()) arr = [[]for _ in range(N+1)] moneys = [0]+list(map(int, input().split())) for i in range(1, N+1): arr[0].append((moneys[i], i)) for _ in range(M): a, b = map(int, input().split()) arr[a].append((0, b)) arr[b].append((0, a)) def make_friend(): global answer q = [] heapq.heappush(q, (0, 0)) visited = [Fal..
2022. 3. 25.
[백준] 8983번 - 사냥꾼 (파이썬)
# 사냥꾼 import sys input = sys.stdin.readline M, N, L = map(int, input().split()) shots_place = list(map(int, input().split())) animals_place = [] for i in range(N): a, b = map(int, input().split()) animals_place.append((a, b)) answer = 0 shots_place.sort() for a, b in animals_place: start, end = 0, len(shots_place)-1 mid = 0 while start < end: mid = (start+end)//2 if shots_place[mid] < a: start =..
2022. 3. 23.
[백준] 6087번 - 레이저 통신 (파이썬)
# 레이저 통신 from collections import deque import sys input = sys.stdin.readline MAX = sys.maxsize M, N = map(int, input().split()) arr = [] C = [] for i in range(N): arr.append(list(input().strip())) for j in range(M): if arr[i][j] == 'C': C.append((i, j)) start, end = C[0], C[1] dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def bfs(a, b): global answer q = deque() q.append((a, b, -1, 0)) visited = [[0] * ..
2022. 3. 21.
[백준] 20056번 - 마법사 상어와 파이어볼 (파이썬)
# 마법사 상어와 파이어볼 import sys input = sys.stdin.readline dx = [-1, -1, 0, 1, 1, 1, 0, -1] dy = [0, 1, 1, 1, 0, -1, -1, -1] N, M, K = map(int, input().split()) fireball_info = [] for _ in range(M): x, y, big, speed, dir = map(int, input().split()) fireball_info.append([x, y, big, speed, dir]) def fireball_move(): # fireball의 좌표를 집합으로 관리 (중복값없게) fireballs = set() # 각 위치별 fireball 표시 temp = [[[] for _ ..
2022. 3. 20.