1. 개요
2. 해시테이블을 활용한 풀이
import sys
from collections import Counter
def solution():
READ = lambda: sys.stdin.readline().rstrip()
READINT = lambda: int(READ())
READINTLIST = lambda: list(map(int, READ().split()))
T = READINT()
N, A = READINT(), READINTLIST()
M, B = READINT(), READINTLIST()
db = Counter()
answer = 0
for i in range(N):
lastSum = A[i]
db[lastSum] += 1
for j in range(i+1, N):
lastSum += A[j]
db[lastSum] += 1
for i in range(M):
lastSum = B[i]
answer += db[T-lastSum]
for j in range(i+1, M):
lastSum += B[j]
answer += db[T-lastSum]
return answer
print(solution())
Leave a comment