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