🤖 알고리즘

SWEA 1959

키루루 2022. 7. 20. 00:41

🔎 SWEA 1959. 두 개의 숫자열 (D2)

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpoFaAS4DFAUq

💡 풀이

case = int(input())
num = 1

while case > 0 :
    case -= 1

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    max = -1000

    if n < m :
        for i in range(m - n + 1) :
            result = [a[i] * b[i] for i in range(len(a))]
            result = sum(result)
            if result > max :
                max = result
            a.insert(0,0)
    elif n > m :
        for j in range(n - m + 1) :
            result = [a[i] * b[i] for i in range(len(b))]
            result = sum(result)
            if result > max :
                max = result
            b.insert(0,0)
    else :
        result = [a[i] * b[i] for i in range(len(a))]
        result = sum(result)

    print(f'#{num} {max}')
    num += 1

💭 TIL

  • 리스트 a의 길이만큼 연속된 a, b 값에 대한 덧셈 / 곱셈
sum_list = [a[i] + b[i] for i in range(len(a))] 
# [a[0]+b[0], a[1]+b[1], a[2]+b[2], ...]

multi_list = [a[i] * b[i] for i in range(len(a))] 
# [a[0]*b[0], a[1]*b[1], a[2]*b[2], ...]