[NYPC 2023_ Round 1] 연습문제 - 인류의 적 모기 퇴치

지구온난화·2023년 9월 2일
0

NYPC

목록 보기
1/2
import sys
input = sys.stdin.readline

li = []

mosquito_cross = []
mosquito_diagonal = []

N, M = map(int, input().split())
for i in range(N):
    a = list(map(int, input().split()))
    li.append(a)



def cross(i, j):  # 십자 모양
    move_x = [1,-1,0,0]
    move_y = [0,0,1,-1]

    cnt = 0
    for k in range(1,M+1):
        for h in range(4):
            x = i + move_x[h]*k
            y = j + move_y[h]*k
            if(x < 0 or x >= N or y < 0 or y >= N): continue
            cnt += li[x][y]
    
    return cnt + li[i][j]


def diagonal(i,j):  # 대각선 모양
    move_x = [-1,-1,1,1]
    move_y = [-1,1,-1,1]

    cnt = 0
    for k in range(1,M+1):
        for h in range(4):
            x = i + move_x[h]*k
            y = j + move_y[h]*k
            if(x < 0 or x >= N or y < 0 or y >= N): continue
            cnt += li[x][y]

    return cnt + li[i][j]



res = 0
for i in range(N):
    for j in range(N):
        res = max(res, cross(i,j), diagonal(i,j))
        

print(res)

맞는지 모르겠음

0개의 댓글