baekjoon 20260117
This commit is contained in:
parent
9e8ba9a3f4
commit
86fb20e8a2
1
code_study/Baekjoon/python/15964.py
Normal file
1
code_study/Baekjoon/python/15964.py
Normal file
@ -0,0 +1 @@
|
||||
print((lambda x: (x[0]**2 - x[1]**2))(list(map(int, input().split()))))
|
||||
50
code_study/Baekjoon/python/2143.py
Normal file
50
code_study/Baekjoon/python/2143.py
Normal file
@ -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)
|
||||
31
code_study/Baekjoon/python/2143_1.py
Normal file
31
code_study/Baekjoon/python/2143_1.py
Normal file
@ -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)
|
||||
Loading…
x
Reference in New Issue
Block a user