반응형
https://www.acmicpc.net/problem/2143
import collections
import sys
input = sys.stdin.readline
t = int(input())
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i-1]
sum_a = [0] + a
for i in range(1, m):
b[i] += b[i-1]
sum_b = [0] + b
a_dct = collections.defaultdict(int)
for i in range(len(sum_a)-1):
for j in range(i+1, len(sum_a)):
num = sum_a[j] - sum_a[i]
a_dct[num] += 1
b_dct = collections.defaultdict(int)
for i in range(len(sum_b)-1):
for j in range(i+1, len(sum_b)):
num = sum_b[j] - sum_b[i]
b_dct[num] += 1
answer = 0
for key in a_dct:
target = t - key
answer += a_dct[key] * b_dct[target]
print(answer)
댓글