From 537c5683f4de82c4e26131dd2a096f8aa9963160 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Fri, 21 Nov 2025 21:41:44 +0900 Subject: [PATCH] 20251121 baekjoon --- code_study/Baekjoon/swift/2143_1.swift | 33 +++++++++++++ code_study/Baekjoon/swift/2143_2.swift | 65 ++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 code_study/Baekjoon/swift/2143_1.swift create mode 100644 code_study/Baekjoon/swift/2143_2.swift diff --git a/code_study/Baekjoon/swift/2143_1.swift b/code_study/Baekjoon/swift/2143_1.swift new file mode 100644 index 0000000..1f9debb --- /dev/null +++ b/code_study/Baekjoon/swift/2143_1.swift @@ -0,0 +1,33 @@ +if let T = Int(readLine() ?? ""), + let n = Int(readLine() ?? ""), + let inputA = readLine(), + let A = inputA.split(separator: " ").compactMap({Int($0)}) as? [Int], + let m = Int(readLine() ?? ""), + let inputB = readLine(), + let B = inputB.split(separator: " ").compactMap({Int($0)}) as? [Int], + A.count == n , B.count == m +{ + var countSumB = [Int: Int]() + for i in 0..= 0 { + let temp = sumA[left] + sumB[right] + + if T > temp { + left += 1 + } + else if T < temp { + right -= 1 + } + else { + var sameCountA = 0 + let currentSumA = sumA[left] + while left < sumA.count && sumA[left] == currentSumA { + sameCountA += 1 + left += 1 + } + + var sameCountB = 0 + let currentSumB = sumB[right] + while right >= 0 && sumB[right] == currentSumB { + sameCountB += 1 + right -= 1 + } + + ans += sameCountA * sameCountB + } + } + + print(ans) +}