반응형
https://www.acmicpc.net/problem/14500
x_lim, y_lim = map(int, input().split())
t = []
for i in range(x_lim):
t.append(list(map(int,input().split())))
answer = 0
#block 1
for i in range(x_lim):
for j in range(y_lim-3):
num = t[i][j]+t[i][j+1]+t[i][j+2]+t[i][j+3]
if answer < num:
answer = num
for i in range(x_lim-3):
for j in range(y_lim):
num = t[i][j]+t[i+1][j]+t[i+2][j]+t[i+3][j]
if answer < num:
answer = num
#block 2
for i in range(x_lim-1):
for j in range(y_lim-1):
num = t[i][j]+t[i][j+1]+t[i+1][j]+t[i+1][j+1]
if answer < num:
answer = num
# 3*2
for i in range(x_lim-2):
for j in range(y_lim-1):
a = t[i][j] + t[i + 1][j] + t[i + 2][j] + max(t[i + 2][j + 1],t[i + 1][j + 1],t[i][j + 1])
b = t[i][j+1] + t[i+1][j+1] + t[i+2][j+1] + max(t[i][j], t[i+1][j], t[i+2][j])
c = t[i][j] + t[i + 1][j] + t[i + 1][j+1] + t[i + 2][j + 1]
d = t[i+1][j] + t[i + 2][j] + t[i + 1][j+1] + t[i][j + 1]
temp = max(a,b,c,d)
if answer < temp:
answer = temp
# 2*3
for i in range(x_lim-1):
for j in range(y_lim-2):
a = t[i][j] + t[i][j+1] + t[i][j+2] + max(t[i + 1][j],t[i + 1][j+1],t[i + 1][j+2])
b = t[i+1][j] + t[i+1][j + 1] + t[i+1][j + 2] + max(t[i][j],t[i][j+1],t[i][j+2])
c = t[i+1][j]+t[i][j+1]+t[i+1][j+1]+t[i][j+2]
d = t[i][j]+t[i][j+1]+t[i+1][j+1]+t[i+1][j+2]
temp = max(a, b, c, d)
if answer < temp:
answer = temp
print(answer)
회전과 뒤집기까지 생각해서 모든 경우를 그려보고 해당 경우를 모두 탐색해보는 구현 문제.
댓글