백준14500(파이썬) - 테트로미노
resilient
·2021. 7. 14. 11:08
728x90
반응형
https://www.acmicpc.net/problem/14500
- 이 문제는 구현문제이다.
- 어떻게 풀까 생각하다가 테트로미노가 놓여질 수 있는 모든 상황을 고려해야 한다는 점을 생각하게 되었고, 함수로 다작성했다.(너무 무식한방법이였다.)
- 경우의 수가 19가지가 나와서 함수가 19개가 되었다... 더 효율적으로 풀 수 있는 방법도 찾아봐야 겠다.
- 그 다음으로는 놓여질 수 있는 모든 상황을 고려하기 위해 2중 for문을 돌면서 각각 놓이는 범위가 다르기 때문에 범위 또한 고려해주었다.
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
data = [list(map(int,input().split())) for _ in range(n)]
graph = [[0]*m for _ in range(n)]
def straight(x,y):
ans = 0
ans += data[x][y]
ans += data[x][y+1]
ans += data[x][y+2]
ans += data[x][y+3]
return ans
def straight_rotate(x,y):
ans = 0
ans += data[x][y]
ans += data[x+1][y]
ans += data[x+2][y]
ans += data[x+3][y]
return ans
def square(x,y):
ans = 0
ans += data[x][y]
ans += data[x][y+1]
ans += data[x+1][y]
ans += data[x+1][y+1]
return ans
def zigzag(x,y):
ans = 0
ans += data[x][y]
ans += data[x+1][y]
ans += data[x+1][y+1]
ans += data[x+2][y+1]
return ans
def zigzag_rotate(x,y):
ans = 0
ans += data[x+1][y]
ans += data[x+1][y+1]
ans += data[x][y+1]
ans += data[x][y+2]
return ans
def zigzag_rev(x,y):
ans = 0
ans += data[x+1][y]
ans += data[x+2][y]
ans += data[x+1][y+1]
ans += data[x][y+1]
return ans
def zigzag_rev_rotate(x,y):
ans = 0
ans += data[x][y]
ans += data[x][y+1]
ans += data[x+1][y+1]
ans += data[x+1][y+2]
return ans
def t(x,y):
ans = 0
ans += data[x][y]
ans += data[x][y+1]
ans += data[x][y+2]
ans += data[x+1][y+1]
return ans
def t_rotate1(x,y):
ans = 0
ans += data[x][y]
ans += data[x+1][y]
ans += data[x+2][y]
ans += data[x+1][y+1]
return ans
def t_rotate2(x,y):
ans = 0
ans += data[x][y+1]
ans += data[x+1][y]
ans += data[x+1][y+1]
ans += data[x+1][y+2]
return ans
def t_rotate3(x,y):
ans = 0
ans += data[x+1][y]
ans += data[x+1][y+1]
ans += data[x][y+1]
ans += data[x+2][y+1]
return ans
def others1(x,y):
ans = 0
ans += data[x][y]
ans += data[x+1][y]
ans += data[x+2][y]
ans += data[x+2][y+1]
return ans
def others2(x,y):
ans = 0
ans += data[x+2][y]
ans += data[x+2][y+1]
ans += data[x+1][y+1]
ans += data[x][y+1]
return ans
def others3(x,y):
ans = 0
ans += data[x][y+2]
ans += data[x+1][y+2]
ans += data[x+1][y+1]
ans += data[x+1][y]
return ans
def others4(x,y):
ans = 0
ans += data[x][y]
ans += data[x][y+1]
ans += data[x][y+2]
ans += data[x+1][y+2]
return ans
def others5(x,y):
ans = 0
ans += data[x][y]
ans += data[x][y+1]
ans += data[x+1][y+1]
ans += data[x+2][y+1]
return ans
def others6(x,y):
ans = 0
ans += data[x][y]
ans += data[x][y+1]
ans += data[x+1][y]
ans += data[x+2][y]
return ans
def others7(x,y):
ans = 0
ans += data[x][y]
ans += data[x+1][y]
ans += data[x][y+1]
ans += data[x][y+2]
return ans
def others8(x,y):
ans = 0
ans += data[x][y]
ans += data[x+1][y]
ans += data[x+1][y+1]
ans += data[x+1][y+2]
return ans
result = 0
for i in range(n):
for j in range(m):
if 0<= i <n-3 and 0 <= j <m:
result = max(result,straight_rotate(i,j))
for i in range(n):
for j in range(m):
if 0<= i <n and 0<= j <m-3:
result = max(result,straight(i,j))
for i in range(n):
for j in range(m):
if 0<= i <n-1 and 0<= j <m-1:
result = max(result,square(i,j))
for i in range(n):
for j in range(m):
if 0<= i <n-1 and 0<= j <m-2:
result = max(result,
zigzag_rev_rotate(i,j),zigzag_rotate(i,j),
t(i,j),t_rotate2(i,j),
others3(i,j),others4(i,j),others7(i,j),others8(i,j)
)
for i in range(n):
for j in range(m):
if 0<= i <n-2 and 0<= j <m-1:
result = max(result,
zigzag_rev(i,j),zigzag(i,j),
t_rotate1(i,j),t_rotate3(i,j),
others1(i,j),others2(i,j),others5(i,j),others6(i,j)
)
print(result)
반응형
'자료구조 & 알고리즘 > 백준(Baekjoon)' 카테고리의 다른 글
백준1759(파이썬) - 암호만들기 (0) | 2021.07.16 |
---|---|
백준10972(파이썬) - 다음 순열 (0) | 2021.07.15 |
백준10819(파이썬) - 차이를 최대로 (0) | 2021.07.12 |
백준10971(파이썬) - 외판원 순회2 (0) | 2021.07.11 |
백준1495(파이썬) - 기타리스트 (2) | 2021.07.10 |