본문 바로가기

전체 글88

[Programmers] Python 합승 택시 요금 (72413) https://school.programmers.co.kr/learn/courses/30/lessons/72413 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 다익스트라 응용 문제이다.1. a, b 각각 가는 비용을 다익스트라로 구한다.2. a, b 각각 구한 비용을 중심으로 비교할 대상을 반복을 돌며, (s -> i 의 동행 거리) + (i -> a 거리) + (i -> b 거리) 가 최소가 되는 것을 찾으면 된다. import heapqdef solution(n, s, a, b, fares): answer = 0 graph=[[] for _ in range(n+1)] for sta.. 2025. 2. 22.
[BOJ] Python 택배(1719) https://www.acmicpc.net/problem/1719  플로이드 워셜로 푸는 대표적인 문제이다.거리 배열 외에도 정답배열을 통해 최단 경로시 가장 먼저 접근해야하는 노드의 값을 테이블로 만들어야 한다. import sysinput = sys.stdin.readlineN,M = map(int,input().split())distance = [[float('inf')] * (N+1) for _ in range(N+1)]graph = [[0] * (N+1) for _ in range(N+1)]for _ in range(M): s,e,cost = map(int,input().split()) if distance[s][e] > cost: distance[s][e] = cost .. 2025. 2. 21.
[BOJ] Python 회문(17609) https://www.acmicpc.net/problem/17609   히든 케이스를 잘 고려해야하는 문제이다.또한, 파이썬은 시간 초과 상황이 발생할 수 있으므로 잘 확인하면 풀어야 한다. import sysinput = sys.stdin.readlineTC = int(input())for _ in range(TC): s = input().rstrip() if s == s[::-1]: print(0) continue start = 0 end = len(s) - 1 while start    회고.예외 상황이 너무 많고 히든케이스가 너무 많아 틀릴 수 있는 가능성이 너무 높았던거 같다... 2025. 2. 20.
[BOJ] Python 플로이드(11404) https://www.acmicpc.net/problem/11404  대표적인 플로이드 워셜 문제이다. 모든 경로에서의 최단경로를 출력하는 문제이다. 3중 for 문을 통해 값을 최신화 한다. import sysinput = sys.stdin.readlineN = int(input())M = int(input())graph = [[] for _ in range(N+1)]distance = [[float('inf')]*(N+1) for _ in range(N+1)]for i in range(1, N+1): distance[i][i] = 0for _ in range(M): s,e,cost = map(int,input().split()) if distance[s][e] > cost: .. 2025. 2. 18.