파리퇴치3

최민수·2023년 7월 11일
0

알고리즘

목록 보기
63/94
def edgeCheck(r, c):
    if 0 <= r < N and 0 <= c < N:
        return True


def launchPlus(r, c):
    result = graph[r][c]
    for depth in range(1, M):
        if edgeCheck(r, c+depth):
            result += graph[r][c+depth]
        if edgeCheck(r, c-depth):
            result += graph[r][c-depth]
        if edgeCheck(r+depth, c):
            result += graph[r+depth][c]
        if edgeCheck(r-depth, c):
            result += graph[r-depth][c]
    return result


def launchCross(r, c):
    result = graph[r][c]
    for depth in range(1, M):
        if edgeCheck(r+depth, c + depth):
            result += graph[r+depth][c + depth]
        if edgeCheck(r+depth, c - depth):
            result += graph[r+depth][c - depth]
        if edgeCheck(r-depth, c-depth):
            result += graph[r-depth][c-depth]
        if edgeCheck(r-depth, c+depth):
            result += graph[r - depth][c+depth]
    return result


T = int(input())
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
for test_case in range(1, T + 1):
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    answer = 0

    for i in range(N):
        temp = map(int, input().split())
        for item in temp:
            graph[i].append(item)

    # 분사
    for row in range(N):
        for col in range(N):
            answer = max(answer, launchPlus(row, col))
            answer = max(answer, launchCross(row, col))

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

D2

단순한 오타로 시간이 좀 걸렸었는데 로직 자체는 어렵지 않았다.
꼼꼼하게 + 형태 체크하고 x 형태 체크하는 구현 능력 문제였음


출처: https://swexpertacademy.com/main/talk/solvingClub/problemView.do?solveclubId=AYj2mga6ZewDFASl&contestProbId=AXuARWAqDkQDFARa&probBoxId=AYj2nEQ6ZfkDFASl&type=USER&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개의 댓글