Algorithm/BOJ133 [백준] 2467번 - 용액 (파이썬) # 용액 import sys input = sys.stdin.readline N = int(input()) arr = list(map(int, input().split())) left, right = 0, N-1 value = sys.maxsize answer = [] while left < right: if abs(arr[left]+arr[right]) 0: right -= 1 else: break print(*answer) 투포인터 1. 처음과 끝의 인덱스를 left와 right으로 설정 2. left < right 일 동안 - 두 용액 합의 절댓값이 현재 value보다 작거나 같으면 answer에 두 용액, value에 현재 값 - 두 용액의 합이 0보다 작으면 left+=1 - 두 용액의 합이 0.. 2022. 3. 25. [백준] 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. [백준] 14938번 - 서강그라운드 (파이썬) # 서강그라운드 import sys input = sys.stdin.readline N, m, r = map(int, input().split()) item = [0] + list(map(int, input().split())) arr = [[sys.maxsize for _ in range(N+1)] for _ in range(N+1)] for i in range(N+1): arr[i][i] = 0 for _ in range(r): a, b, dist = map(int, input().split()) arr[a][b] = dist arr[b][a] = dist for k in range(N+1): for i in range(N+1): for j in range(N+1): if arr[i][j] > arr.. 2022. 3. 24. [백준] 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. [백준] 1941번 - 소문난 칠공주 (파이썬) # 소문난 칠공주 from collections import defaultdict import sys input = sys.stdin.readline arr = [] for _ in range(5): arr.append(list(input().strip())) visited = defaultdict(bool) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def back_tracking(people): global result # (해당 people의 숫자를 arr좌표상의 문자열로 바꿔서 문자열로 join)의 'Y'의 개수 if (''.join([arr[i//5][i % 5] for i in people]).count('Y')) > 3: return # 7명이라면 if len(peo.. 2022. 3. 22. [백준] 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. 이전 1 ··· 3 4 5 6 7 8 9 ··· 19 다음