Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

yeonseong

브루트포스 백준 14500번 테트로미노 - 파이썬(Python), 1912ms 통과 본문

알고리즘

브루트포스 백준 14500번 테트로미노 - 파이썬(Python), 1912ms 통과

yeonseong.dev 2024. 5. 30. 00:34

문제링크

https://www.acmicpc.net/problem/14500

정답

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
info = []
res = 0

def count_case(shape):
    cnt = 0
    for e in shape:
        y, x = e
        if y < 0 or y >= n or x < 0 or x >= m:
            return 0
        cnt += info[y][x]
    return cnt


def max_count(i, j):
    # - block
    case_1 = count_case([(i, j), (i+1, j), (i+2, j), (i+3, j)])
    case_2 = count_case([(i, j), (i, j+1), (i, j+2), (i, j+3)])
    # ㅁ block
    case_3 = count_case( [(i, j), (i, j+1), (i+1, j), (i+1, j+1)])
    # L block 세로
    case_4 = count_case([(i, j), (i+1, j), (i+2, j), (i+2, j+1)])
    case_5 = count_case([(i, j), (i+1, j), (i+2, j), (i+2, j-1)])
    case_6 = count_case([(i, j), (i, j+1), (i+1, j+1), (i+2, j+1)])
    case_7 = count_case([(i, j), (i, j+1), (i+1, j), (i+2, j)])
    # L block 가로
    case_8 = count_case([(i, j), (i, j+1), (i, j+2), (i+1, j+2)])
    case_9 = count_case([(i, j), (i, j+1), (i, j+2), (i-1, j+2)])
    case_10 = count_case([(i, j), (i+1, j), (i+1, j+1), (i+1, j+2)])
    case_11 = count_case([(i, j), (i+1, j), (i, j+1), (i, j+2)])
    # S block
    case_12 = count_case([(i, j), (i+1, j), (i+1, j+1), (i+2, j+1)])
    case_13 = count_case([(i, j), (i+1, j), (i+1, j-1), (i+2, j-1)])
    case_14 = count_case([(i, j), (i, j+1), (i-1, j+1), (i-1, j+2)])
    case_15 = count_case([(i, j), (i, j+1), (i+1, j+1), (i+1, j+2)])
    # ㅗ block
    case_16 = count_case([(i, j), (i+1, j), (i-1, j), (i, j+1)])
    case_17 = count_case([(i, j), (i+1, j), (i-1, j), (i, j-1)])
    case_18 = count_case([(i, j), (i, j+1), (i, j-1), (i+1, j)])
    case_19 = count_case([(i, j), (i, j+1), (i, j-1), (i-1, j)])

    return max(case_1, case_2, case_3, case_4, case_5, case_6, case_7, case_8, case_9, case_10, case_11, case_12, case_13, case_14, case_15, case_16, case_17, case_18, case_19)


for _ in range(n):
    line = list(map(int, input().split()))
    info.append(line)

for i in range(n):
    for j in range(m):
        res = max(max_count(i, j), res)

print(res)

주의사항

순회할 block의 모양을 주의하여 i, j를 결정해줘야한다.

통과시간

'알고리즘' 카테고리의 다른 글

[백준 13412] 서로소 쌍 파이썬  (0) 2024.06.19