두 개의 숫자열

최민수·2023년 7월 12일
0

알고리즘

목록 보기
66/94
T = int(input())
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
for test_case in range(1, T + 1):
    N, M = map(int, input().split())
    answer = -987654321

    aTemp = list(map(int, input().split()))
    bTemp = list(map(int, input().split()))

    alen, blen = len(aTemp), len(bTemp)
    if alen > blen:
        for i in range(alen-blen+1):
            temp = aTemp[i:i + blen]
            result = 0
            for aitem, bitem in zip(bTemp, temp):
                result += aitem * bitem
            answer = max(answer, result)
    else:
        for i in range(blen-alen+1):
            temp = bTemp[i:i+alen]
            result = 0
            for aitem, bitem in zip(aTemp, temp):
                result += aitem*bitem
            answer = max(answer, result)

    print("#" + str(test_case) + " " + str(answer))

D2

단순한 linear 구현이었지만 범위 index 설정을 잘못해서 두 번 틀림..

이 부분 신경써야겠음!


출처:https://swexpertacademy.com/main/talk/solvingClub/problemView.do?solveclubId=AYj2mga6ZewDFASl&contestProbId=AV5PpoFaAS4DFAUq&probBoxId=AYj2nEQ6ZfkDFASl&type=PROBLEM&problemBoxTitle=%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98+Track+%28%EB%82%9C%EC%9D%B4%EB%8F%84+%EC%A4%91%29&problemBoxCnt=5

profile
CS, 개발 공부기록 🌱

0개의 댓글