공부-코딩테스트/코테풀이 - 자바, 파이썬
2001. 파리 퇴치 (코딩테스트, SW Expert Academy)
령과
2022. 5. 6. 01:25
문제
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PzOCKAigDFAUq
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
나의 코드 : 23분 34초
T = int(input())
for test_case in range(1, T + 1):
N, M = map(int, input().split())
table = [list(map(int,input().split())) for i in range(N)]
sum_table = []
answer = 0
for i in range(N):
tmp = [sum(table[i][j:j+M]) for j in range(N-M+1)]
sum_table.append(tmp)
sum_table = list(map(list,zip(*sum_table)))
for i in range(len(sum_table)):
for j in range(N-M+1):
answer = max(answer,sum(sum_table[i][j:j+M]))
print("#"+str(test_case),answer)
그냥 비슷한 형식의 for문 두번을 써서 가로, 세로별 합산을 구해서 나오는 수의 최대값을 return하는 단순한 문제
쉬운문제인데 왜이리 시간을 오래 쓰는지 모르겠네..... 더 익숙해져야된다.