(삼성) - 테트로미노(14500)
삼성 역량테스트 - 구현, 브루트포스
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)]
answer = 0
tetromino = [
[(0,0), (0,1), (1,0), (1,1)],
[(0,0), (0,1), (0,2), (0,3)],
[(0,0), (1,0), (2,0), (3,0)],
[(0,0), (0,1), (0,2), (1,0)],
[(1,0), (1,1), (1,2), (0,2)],
[(0,0), (1,0), (1,1), (1,2)],
[(0,0), (0,1), (0,2), (1,2)],
[(0,0), (1,0), (2,0), (2,1)],
[(2,0), (2,1), (1,1), (0,1)],
[(0,0), (0,1), (1,0), (2,0)],
[(0,0), (0,1), (1,1), (2,1)],
[(0,0), (0,1), (0,2), (1,1)],
[(1,0), (1,1), (1,2), (0,1)],
[(0,0), (1,0), (2,0), (1,1)],
[(1,0), (0,1), (1,1), (2,1)],
[(1,0), (2,0), (0,1), (1,1)],
[(0,0), (1,0), (1,1), (2,1)],
[(1,0), (0,1), (1,1), (0,2)],
[(0,0), (0,1), (1,1), (1,2)]
]
def find(x, y):
global answer
for i in range(19):
result = 0 # 각 테트로미노 4개 값 누적
for j in range(4):
# try, except 예외처리 -> 범위 벗어난 인덱스처리
try:
nextX = x + tetromino[i][j][0]
nextY = y + tetromino[i][j][1]
result += board[nextX][nextY] # 누적
except IndexError:
continue
answer = max(answer, result) # 최대값 갱신
for i in range(n):
for j in range(m):
find(i, j)
print(answer)
try, except를 알고리즘 때 사용을 잘 안했지만 이 문제에 대단히 유용.
참고)
https://jeongchul.tistory.com/670
https://choichumji.tistory.com/98
Author And Source
이 문제에 관하여((삼성) - 테트로미노(14500)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@skkfea07/백준삼성-테트로미노14500저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)