링크 : https://www.acmicpc.net/problem/16236 16236번: 아기 상어 N×N 크기의 공간에 물고기 M마리와 아기 상어 1마리가 있다. 공간은 1×1 크기의 정사각형 칸으로 나누어져 있다. 한 칸에는 물고기가 최대 1마리 존재한다. 아기 상어와 물고기는 모두 크기를 가 www.acmicpc.net 코드 from collections import deque n = int(input()) sx,sy = -1,-1 graph = [] eat_cnt, fish_cnt, time, size = 0, 0, 0, 2 dx,dy = [-1,0,0,1],[0,-1,1,0] for i in range(n): l = list(map(int,input().split())) for j in ran..
링크 : https://www.acmicpc.net/problem/1238 1238번: 파티 첫째 줄에 N(1 ≤ N ≤ 1,000), M(1 ≤ M ≤ 10,000), X가 공백으로 구분되어 입력된다. 두 번째 줄부터 M+1번째 줄까지 i번째 도로의 시작점, 끝점, 그리고 이 도로를 지나는데 필요한 소요시간 Ti가 들어 www.acmicpc.net 코드 import sys input = sys.stdin.readline import heapq def dijkstra(start): Q = [] heapq.heappush(Q,(0,start)) dist = [1e9] * (n + 1) dist[start] = 0 while Q: total, node = heapq.heappop(Q) if dist[node..
링크 : https://www.acmicpc.net/problem/13308 13308번: 주유소 표준 입력으로 다음 정보가 주어진다. 첫 번째 줄에는 도시의 수와 도로의 수를 나타내는 정수 N(2 ≤ N ≤ 2,500)과 정수 M(1 ≤ M ≤ 4,000)이 주어진다. 다음 줄에 각 도시 주유소의 리터당 가격이 도 www.acmicpc.net 코드 import heapq,sys input=sys.stdin.readline n,m = map(int,input().split()) price = [0]+list(map(int,input().split())) graph = [[] for _ in range(n + 1)] for _ in range(m): a,b,w = map(int,input().split()..
링크 : https://www.acmicpc.net/problem/2887 2887번: 행성 터널 첫째 줄에 행성의 개수 N이 주어진다. (1 ≤ N ≤ 100,000) 다음 N개 줄에는 각 행성의 x, y, z좌표가 주어진다. 좌표는 -109보다 크거나 같고, 109보다 작거나 같은 정수이다. 한 위치에 행성이 두 개 이 www.acmicpc.net 코드 import sys input = sys.stdin.readline def find(node): if parent[node] != node: parent[node] = find(parent[node]) return parent[node] n = int(input()) xlst, ylst, zlst = [],[],[] for i in range(n): ..
링크 : https://www.acmicpc.net/problem/2565 2565번: 전깃줄 첫째 줄에는 두 전봇대 사이의 전깃줄의 개수가 주어진다. 전깃줄의 개수는 100 이하의 자연수이다. 둘째 줄부터 한 줄에 하나씩 전깃줄이 A전봇대와 연결되는 위치의 번호와 B전봇대와 연결되는 www.acmicpc.net 코드 import bisect def LIS(arr): res = [arr[0]] for x in arr[1:]: if x < res[-1]: res[bisect.bisect_left(res,x)] = x continue res.append(x) return len(res) n = int(input()) line = sorted([list(map(int,input().split())) for _..
링크 : https://www.acmicpc.net/problem/11578 11578번: 팀원 모집 3번 학생과 4번 학생을 선택하면 1번부터 5번까지 모든 문제를 풀 수 있는 팀을 만들 수 있다. 1번, 2번, 4번 학생을 선택해도 모든 문제를 다 풀 수 있지만 팀원의 수가 3명이라 답이 될 수 없다. www.acmicpc.net 코드 def DFS(idx,cnt,total): global answer if total == target: answer = min(answer,cnt) return if idx >= m: return DFS(idx+1, cnt+1, total | students[idx]) DFS(idx+1, cnt, total) n,m = map(int,input().split()) st..