🐣/BOJ(11)
-
6603 swift - 로또
어떻게든 조합으로 풀어보려고 노력.조합은 여기 [Swift] 순열 / permutation / 조합 / combinationfunc permutation(_ target: [String], _ targetNum: Int) { var result: [[String]] = [] var check = [Bool](repeating: false, count: target.count) func permute(_ arr: [String]) { if arr.count == targetNum { result.append(arr) return } for i in 0..chanhhh.tistory.com문제 개요는 이것.7 1 2 3 4 5 6 78 1 2 3 5 8 13 21 340input의 첫번째 숫자만큼 수가 주어..
2024.04.28 -
1946 swift - 신입 사원 / 시간 초과 해결
Greedy 사용 [Swift] Greedy / 그리디 / 탐욕 알고리즘 그리디 알고리즘이란? Greedy algorithm은 최적해를 구하는 데에 사용되는 근사적인 방법으로, 여러 경우 중 하나를 결정해야 할 때마다 그 순간에 최적이라고 생각되는 것을 선택해 나가는 방식으 chanhhh.tistory.com 지원자의 서류심사 성적으로 sort하면 O(NlogN)으로 maxInterviewRank로 where절을 사용해서 아래와 같은 코드로 2NlogN의 시간을 가지고 문제를 풀 수 있지만, 아래의 코드는 백준의 Swift 의 느린 입력으로 인해 시간초과를 받을 수 밖에 없다 let T = Int(readLine()!)! for _ in 0..= 48, now
2024.03.10 -
14171 swift - Cities and States
[Swift] (자료구조) 해쉬 / Hash chanhhh.tistory.com 처음에 시간 제한이 2초라서 널널하게 보고 2중 for문을 돌렸다가 호되게 시간초과 맞고, 두번째는 저장부터 해시로 저장하자 했는데 중복 값때문에 호되게 틀렸습니다. 14171번: Cities and States To keep his cows intellectually stimulated, Farmer John has placed a large map of the USA on the wall of his barn. Since the cows spend many hours in the barn staring at this map, they start to notice several curious patterns. For exa..
2024.03.06 -
1967 swift - 트리의 지름
₩BFS 사용 [Swift] Breadth-First Search / BFS BFS (Breadth-First Search) 인접한 노드를 먼저 탐색하는 방식. O(Vertex+Edge) A→B→C→D→E→F→G→H 해당하는 그래프는 아래와 같이 인접 리스트로 나타낼 수 있다. let graph: [String: [String]] = [ "A" : ["B", "C"], chanhhh.tistory.com 1. 접근방법. 결국엔 Leaf 에서 Leaf의 길이를 재는 거니까, Leaf에서 갈 수 있는 모든 Leaf 들을 BFS로 탐색하여 가장 긴 것을 찾으면 된다고 판단. => 시간 초과 더보기 var n = Int(readLine()!)! var N = Array(repeating: 1, count: n)..
2024.02.07 -
11404 swift - 플로이드
플로이드 워셜 알고리즘 사용 [그래프] 플로이드 워셜(Floyd-Warshall Algorithm) 플로이드 워셜(Floyd-Warshall Algorithm) 컴퓨터 과학에서 플로이드-워셜 알고리즘(Floyd-Warshall Algorithm)은 변의 가중치가 음이거나 양인 (음수 사이클은 없는) 가중 그래프에서 최단 경로들을 찾는 알고 chanhhh.tistory.com 중간노드를 거쳐서 갈 수 있는 경우를 고려하여 3중 for문으로 코드를 작성합니다. import Foundation var n = Int(readLine()!)! var cost = Array(repeating: Array(repeating: 987654321, count: n), count: n) for _ in 0..
2024.02.05