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) +}