Skip to content

Latest commit

 

History

History
78 lines (65 loc) · 1.61 KB

3019.md

File metadata and controls

78 lines (65 loc) · 1.61 KB

3019

Python

# 더 좋은 풀이
blocks = {
    1: [[0, 0, 0, 0], [0]],
    2: [[0, 0]],
    3: [[0, 0, 1], [1, 0]],
    4: [[1, 0, 0], [0, 1]],
    5: [[0, 0, 0], [1, 0], [0, 1], [1, 0, 1]],
    6: [[0, 0, 0], [2, 0], [0, 1, 1], [0, 0]],
    7: [[0, 0, 0], [0, 0], [1, 1, 0], [0, 2]]
}

C, P = map(int, input().split())
lst = list(map(int, input().split()))

ans = 0
for block in blocks[P]:
    for i in range(C-len(block)+1):
        start_height = lst[i] - block[0]
        for j in range(len(block)):
            if start_height != lst[i+j] - block[j]:
                break
        else:
            ans += 1

print(ans)
# 내 풀이
C, P = map(int, input().split())
lst = list(map(int, input().split()))

def four_flat():
    ret = 0
    for i in range(C-3):
        if lst[i] == lst[i+1] == lst[i+2] == lst[i+3]:
            ret += 1
    return ret

def three_flat(l=0, r=0):
    ret = 0
    for i in range(C-2):
        if lst[i] - l == lst[i+1] == lst[i+2] - r:
            ret += 1
    return ret

def two_flat(l=0, r=0):
    ret = 0
    for i in range(C-1):
        if lst[i] - l == lst[i+1] - r:
            ret += 1
    return ret

ans = 0
if P == 1:
    ans = C + four_flat()
elif P == 2:
    ans = two_flat()
elif P == 3:
    ans = two_flat(1, 0) + three_flat(0, 1)
elif P == 4:
    ans = two_flat(0, 1) + three_flat(1, 0)
elif P == 5:
    ans = two_flat(1, 0) + two_flat(0, 1) + three_flat() + three_flat(1, 1)
elif P == 6:
    ans = two_flat(2, 0) + two_flat() + three_flat(-1, 0) + three_flat()
elif P == 7:
    ans = two_flat(0, 2) + two_flat() + three_flat(0, -1) + three_flat()

print(ans)