Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- RxSwift
- task cancellation
- SWIFT
- BFS
- uikit toast
- Tuist
- traits
- swift dashed line
- custombottomsheet
- task cancel
- rxdatasources
- swift 백준
- swift bottomsheet
- coordinator
- custom navigation bar
- 타임라인 포맷팅
- button configuration
- claen architecture
- custom ui
- reactorkit
- identifiable
- paragraph style
- swift 점선
- UIKit
- swift navigationcontroller
- swift concurrency
- DP
- tusit font 추가 방법
- domain data
- swift custom ui
Archives
- Today
- Total
김경록의 앱 개발 여정
[Swift 백준] 14248 점프 점프 본문
https://www.acmicpc.net/problem/14248
풀이 아이디어
이차원 그래프를 이용한 그래프탐색 문제입니다
이동방향은 좌 우 모두 가능하므로 [-1, 1] 로 지정합니다.
풀이
let n = Int(readLine()!)!
let graph = readLine()!.split(separator: " ").map { Int($0)! }
//인덱스 맞추기
let s = Int(readLine()!)! - 1
var isvisited = Array(repeating: false, count: n)
let direction = [-1, 1]
func dfs(position: Int) {
if position < 0 || position >= n || isvisited[position] == true {
return
}
isvisited[position] = true
let jump = graph[position]
for dir in direction {
let next = position + jump * dir
dfs(position: next)
}
}
dfs(position: s)
print(isvisited.filter { $0 == true }.count)
'Algorithm' 카테고리의 다른 글
[Swift 백준] 1303 전쟁 - 전투 (0) | 2025.03.25 |
---|---|
[Swift 백준] 1927 최소 힙 (0) | 2025.03.14 |
[Swift 백준] 16173 점프왕 쩰리 (Small) (0) | 2025.03.05 |
[Swift 백준] 24480 알고리즘 수업 - 깊이 우선 탐색 2 (0) | 2025.02.26 |
[Swift 백준] 7785 회사에 있는 사람 (0) | 2025.02.20 |