From bad8a6f6ff51572fbc6556909c684a16c0832f57 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sun, 17 Aug 2025 22:31:44 +0900 Subject: [PATCH] 20250817 baekjoon --- code_study/Baekjoon/swift/16928.swift | 90 +++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 code_study/Baekjoon/swift/16928.swift diff --git a/code_study/Baekjoon/swift/16928.swift b/code_study/Baekjoon/swift/16928.swift new file mode 100644 index 0000000..cf8d8f3 --- /dev/null +++ b/code_study/Baekjoon/swift/16928.swift @@ -0,0 +1,90 @@ +public struct Deque { + private var front: [T] = [] + private var back: [T] = [] + + public var isEmpty: Bool { + return front.isEmpty && back.isEmpty + } + + public var count: Int { + return front.count + back.count + } + + public mutating func append(_ element: T) { + back.append(element) + } + + public mutating func prepend(_ element: T) { + front.append(element) + } + + public mutating func popFirst() -> T? { + if front.isEmpty { + front = back.reversed() + back.removeAll() + } + return front.popLast() + } + + public mutating func popLast() -> T? { + if back.isEmpty { + back = front.reversed() + front.removeAll() + } + return back.popLast() + } +} + +if let input = readLine(), + let nm = { + let numList = input.split(separator : " ").compactMap({Int($0)}) + return numList.count==2 ? numList : nil + }() as [Int]? { + let N = nm[0] + let M = nm[1] + var q: Deque<(Int, Int)> = Deque() + var snake_ladder: [Int: Int] = Dictionary(uniqueKeysWithValues: zip(1...100, 1...100)) + var visited: [Bool] = Array(repeating: false, count: 101) + + for _ in 0..