diff --git a/code_study/Baekjoon/python/15964.py b/code_study/Baekjoon/python/15964.py new file mode 100644 index 0000000..0ee1400 --- /dev/null +++ b/code_study/Baekjoon/python/15964.py @@ -0,0 +1 @@ +print((lambda x: (x[0]**2 - x[1]**2))(list(map(int, input().split())))) \ No newline at end of file diff --git a/code_study/Baekjoon/python/2143.py b/code_study/Baekjoon/python/2143.py new file mode 100644 index 0000000..b8c43c1 --- /dev/null +++ b/code_study/Baekjoon/python/2143.py @@ -0,0 +1,50 @@ +import sys +input = sys.stdin.readline + +T = int(input()) +n, A = int(input()), list(map(int, input().split())) +m, B = int(input()), list(map(int, input().split())) + +sumA = [] +for i in range(n) : + currentSum = 0 + for a in A[i:] : + currentSum += a + sumA.append(currentSum) + +sumB = [] +for i in range(m) : + currentSum = 0 + for b in B[i:] : + currentSum += b + sumB.append(currentSum) + +sumA.sort() +sumB.sort() + +L, R = 0, len(sumB) - 1 +ans = 0 + +while L < len(sumA) and R >= 0 : + a, b = sumA[L], sumB[R] + + if a + b == T: + na = 0 + while L < len(sumA) and a == sumA[L] : + L += 1 + na += 1 + + nb = 0 + while R >= 0 and b == sumB[R] : + R -= 1 + nb += 1 + + ans += na*nb + + else : + if a + b > T : + R -= 1 + else : + L += 1 + +print(ans) \ No newline at end of file diff --git a/code_study/Baekjoon/python/2143_1.py b/code_study/Baekjoon/python/2143_1.py new file mode 100644 index 0000000..8322802 --- /dev/null +++ b/code_study/Baekjoon/python/2143_1.py @@ -0,0 +1,31 @@ +from collections import Counter +import sys +input = sys.stdin.readline + +T = int(input()) +n, A = int(input()), list(map(int, input().split())) +m, B = int(input()), list(map(int, input().split())) + +sumA = [] +for i in range(n) : + currentSum = 0 + for a in A[i:] : + currentSum += a + sumA.append(currentSum) + +sumB = [] +for i in range(m) : + currentSum = 0 + for b in B[i:] : + currentSum += b + sumB.append(currentSum) + +countA = Counter(sumA) +countB = Counter(sumB) + +ans = 0 +for key in countA : + target = T - key + ans += countA[key]*countB[target] + +print(ans) \ No newline at end of file