728x90
- 문제
- 해결
import sys
height, width = [int(x) for x in sys.stdin.readline().split()]
mapping = [list(map(int, x.split())) for x in sys.stdin.readlines()]
case_to_sub = {
0: 2,
1: 1,
2: 8,
3: 4,
4: 4
}
def case_sub_to_available(case, sub, total_row, total_col):
if case == 0 and sub == 0:
return total_row, total_col - 3, 0, 0
elif case == 0 and sub == 1:
return total_row - 3, total_col, 0, 0
elif case == 1 and sub == 0:
return total_row - 1, total_col - 1, 0, 0
elif case == 2 and sub == 0:
return total_row - 2, total_col - 1, 0, 0
elif case == 2 and sub == 1:
return total_row - 1, total_col - 2, 0, 0
elif case == 2 and sub == 2:
return total_row - 2, total_col - 1, 0, 0
elif case == 2 and sub == 3:
return total_row - 1, total_col - 2, 1, 0
elif case == 2 and sub == 4:
return total_row - 2, total_col - 1, 2, 0
elif case == 2 and sub == 5:
return total_row - 1, total_col - 2, 0, 0
elif case == 2 and sub == 6:
return total_row - 2, total_col - 1, 0, 0
elif case == 2 and sub == 7:
return total_row - 1, total_col - 2, 0, 0
elif case == 3 and sub == 0:
return total_row - 2, total_col - 1, 0, 0
elif case == 3 and sub == 1:
return total_row - 1, total_col - 2, 1, 0
elif case == 3 and sub == 2:
return total_row - 2, total_col - 1, 1, 0
elif case == 3 and sub == 3:
return total_row - 1, total_col - 2, 0, 0
elif case == 4 and sub == 0:
return total_row - 1, total_col - 2, 0, 0
elif case == 4 and sub == 1:
return total_row - 2, total_col - 1, 1, 0
elif case == 4 and sub == 2:
return total_row - 1, total_col - 2, 1, 0
elif case == 4 and sub == 3:
return total_row - 2, total_col - 1, 0, 0
def get_val(case, sub, r, c, d):
if case == 0 and sub == 0:
return d[r][c] + d[r][c + 1] + d[r][c + 2] + d[r][c + 3]
elif case == 0 and sub == 1:
return d[r][c] + d[r + 1][c] + d[r + 2][c] + d[r + 3][c]
elif case == 1 and sub == 0:
return d[r][c] + d[r + 1][c] + d[r][c + 1] + d[r + 1][c + 1]
elif case == 2 and sub == 0:
return d[r][c] + d[r + 1][c] + d[r + 2][c] + d[r + 2][c + 1]
elif case == 2 and sub == 1:
return d[r][c] + d[r][c + 1] + d[r][c + 2] + d[r + 1][c]
elif case == 2 and sub == 2:
return d[r][c] + d[r][c + 1] + d[r + 1][c + 1] + d[r + 2][c + 1]
elif case == 2 and sub == 3:
return d[r][c] + d[r][c + 1] + d[r][c + 2] + d[r - 1][c + 2]
elif case == 2 and sub == 4:
return d[r][c] + d[r][c + 1] + d[r - 1][c + 1] + d[r - 2][c + 1]
elif case == 2 and sub == 5:
return d[r][c] + d[r][c + 1] + d[r][c + 2] + d[r + 1][c + 2]
elif case == 2 and sub == 6:
return d[r][c] + d[r][c + 1] + d[r + 1][c] + d[r + 2][c]
elif case == 2 and sub == 7:
return d[r][c] + d[r + 1][c] + d[r + 1][c + 1] + d[r + 1][c + 2]
elif case == 3 and sub == 0:
return d[r][c] + d[r + 1][c] + d[r + 1][c + 1] + d[r + 2][c + 1]
elif case == 3 and sub == 1:
return d[r][c] + d[r][c + 1] + d[r - 1][c + 1] + d[r - 1][c + 2]
elif case == 3 and sub == 2:
return d[r][c] + d[r][c + 1] + d[r - 1][c + 1] + d[r + 1][c]
elif case == 3 and sub == 3:
return d[r][c] + d[r][c + 1] + d[r + 1][c + 1] + d[r + 1][c + 2]
elif case == 4 and sub == 0:
return d[r][c] + d[r][c + 1] + d[r][c + 2] + d[r + 1][c + 1]
elif case == 4 and sub == 1:
return d[r][c] + d[r][c + 1] + d[r - 1][c + 1] + d[r + 1][c + 1]
elif case == 4 and sub == 2:
return d[r][c] + d[r][c + 1] + d[r][c + 2] + d[r - 1][c + 1]
elif case == 4 and sub == 3:
return d[r][c] + d[r + 1][c] + d[r + 1][c + 1] + d[r + 2][c]
max_ = 0
for case in case_to_sub.keys():
for sub in range(case_to_sub[case]):
row_cnt, col_cnt, start_row, start_col = case_sub_to_available(case, sub, height, width)
for r in range(start_row, start_row + row_cnt, 1):
for c in range(start_col, start_col + col_cnt, 1):
val = get_val(case, sub, r, c, mapping)
if val > max_:
max_ = val
print(max_)
- 포인트
- Bruteforce
- 모든 도형마다 가능한 좌우대칭 경우를 생성
728x90
'Algorithm-Problems > 백준' 카테고리의 다른 글
[백준][14501] 퇴사 (0) | 2022.05.08 |
---|---|
[백준][13023] ABCDE (0) | 2022.05.08 |
[백준][11724] 연결 요소의 개수 (0) | 2022.05.08 |
[백준][10972] 다음 순열 (0) | 2022.05.08 |
[백준][10819] 차이를 최대로 (0) | 2022.05.08 |