๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ช๐Ÿป์ฝ”๋”ฉํ…Œ์ŠคํŠธ/๋ฐฑ์ค€ & ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[๊ตฌํ˜„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜] 20061 : ๋ชจ๋…ธ๋ฏธ๋…ธ๋„๋ฏธ๋…ธ 2 python

๐Ÿ“„ 20061 : ๋ชจ๋…ธ๋ฏธ๋…ธ๋„๋ฏธ๋…ธ 2  ๐Ÿ“„

www.acmicpc.net/problem/20061

 

20061๋ฒˆ: ๋ชจ๋…ธ๋ฏธ๋…ธ๋„๋ฏธ๋…ธ 2

๋ชจ๋…ธ๋ฏธ๋…ธ๋„๋ฏธ๋…ธ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ƒ๊ธด ๋ณด๋“œ์—์„œ ์ง„ํ–‰๋˜๋Š” ๊ฒŒ์ž„์ด๋‹ค. ๋ณด๋“œ๋Š” ๋นจ๊ฐ„์ƒ‰ ๋ณด๋“œ, ํŒŒ๋ž€์ƒ‰ ๋ณด๋“œ, ์ดˆ๋ก์ƒ‰ ๋ณด๋“œ๊ฐ€ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋ถ™์–ด์žˆ๋Š” ํ˜•ํƒœ์ด๋‹ค. ๊ฒŒ์ž„์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ขŒํ‘œ (x, y)์—์„œ x๋Š” ํ–‰,

www.acmicpc.net


๐Ÿค” ๋ฌธ์ œ ํ’€์ด  ๐Ÿค”

"๊ตฌํ˜„"๊ณผ "์‹œ๋ฎฌ๋ ˆ์ด์…˜"์„ ํ‘ธ๋Š” ๋ฐฉ๋ฒ•์€ ์ž์‹ ๊ฐ์ธ ๊ฒƒ ๊ฐ™๋‹ค. ๋ฌธ์ œ ์กฐ๊ฑด์ด ๊ต‰์žฅํžˆ ๋ณต์žกํ•˜๊ณ  ๊ตฌํ˜„ํ•˜์ž๋‹ˆ ๊ท€์ฐฎ์€ ๋ถ€๋ถ„๋“ค์ด ๋งŽ์ด ๋ณด์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ ํ’€์ด๋ฅผ ํ•˜๊ธฐ ์‹ซ์–ด์ง€๊ฒŒ ๋œ๋‹ค. 

 

ํ•˜์ง€๋งŒ ์ด๋Ÿฐ ๊ตฌํ˜„ ๋ฌธ์ œ๋ฅผ ๋งŽ์ด ํ’€๋‹ค๋ณด๋ฉด ๊ตฌํ˜„์— ๋Œ€ํ•ด ๋‘๋ ค์›€์ด ์‚ฌ๋ผ์ ธ์„œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์‹œ๋„๋ฅผ ์‰ฝ๊ฒŒ ํ•ด๋ณผ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

 

์ด ๋ฌธ์ œ์—์„œ ์–ด๋ ค์› ๋˜ ์ ์€

 

fill_block()ํ•จ์ˆ˜์—์„œ๋Š” 'pre'๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ์ด์ „ ์œ„์น˜๋ฅผ ๊ธฐ์–ตํ•ด์„œ ๋‹ค์Œ ์œ„์น˜๊ฐ€ ๋ธ”๋Ÿญ์ด ์žˆ์„ ๋•Œ 'pre'๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์•„์ด๋””์–ด๊ฐ€ ํ•„์š”ํ–ˆ๋‹ค.

 

cal_score()์—์„œ๋Š” ๋‹จ์ˆœํžˆ ํ•œ ์ค„์ด ๋ชจ๋‘ ์ฑ„์›Œ์ ธ์žˆ์œผ๋ฉด score๋ฅผ ์ฆ๊ฐ€์‹œํ‚ค๊ณ  ๊ทธ ์ค„๋ถ€ํ„ฐ ์‹œ์ž‘์ค„๊นŒ์ง€ ํ•œ ์นธ์”ฉ ๋•ก๊ฒจ์ค˜์•ผ ํ–ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ๋˜๋ฉด ํ˜„์žฌ ์ค„์„ ๋‹ค์‹œ ๊ฒ€์‚ฌํ•ด์•ผํ•˜๋ฏ€๋กœ ๋ฐ”๋กœ ๋‹ค์Œ ์ค„๋กœ ๋„˜์–ด๊ฐ€๋ฉด ์•ˆ๋œ๋‹ค.

 

special_area()์—์„œ๋Š” ์ฒ˜์Œ์—๋Š” ๋ธ”๋Ÿญ์ด ์กด์žฌํ•˜๋Š” ์ค„์˜ ๊ฐฏ์ˆ˜๋งŒํผ ์œ ๋™์ ์œผ๋กœ 1๊ฐœ ๋˜๋Š” 2๊ฐœ๋ฅผ ๋•ก๊ฒจ์ฃผ๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ๊ทธ๊ฒŒ ์–ด๋ ค์› ๋‹ค.

๊ทธ๋ž˜์„œ ๊ทธ๋ƒฅ ๋ธ”๋Ÿญ์ด ์กด์žฌํ•˜๋Š” ํŠน์ˆ˜ ์ค„์˜ ๊ฐฏ์ˆ˜(count)๋ฅผ ์„ธ๊ณ  count๋งŒํผ ํ•œ ์ค„์”ฉ ๋•ก๊ธฐ๋Š” ๋กœ์ง์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์‹คํ–‰ํ•˜๋„๋ก ๊ตฌํ˜„ํ–ˆ๋‹ค.


โŒจ๏ธ ์ฝ”๋“œ โŒจ๏ธ

N = int(input())
# 1 : (1, 1), 2 : (1, 2), 3 : (2, 1)

red = [[0] * 4 for _ in range(4)]

blue = [[0] * 6 for _ in range(4)]
green = [[0] * 4 for _ in range(6)]
score = 0


# ๋ธ”๋Ÿญ์ฑ„์šฐ๊ธฐ
def fill_block(t, x, y):
    if t == 1:
        j = 0
        pre = 0
        while j < 6:
            if blue[x][j] == 0:
                pre = j
                j += 1
            else:
                break
        blue[x][pre] = 1

        i = 0
        pre = 0
        while i < 6:
            if green[i][y] == 0:
                pre = i
                i += 1
            else:
                break
        green[pre][y] = 1
    elif t == 2:
        j = 0
        pre = 0
        while j < 5:
            if blue[x][j] == 0 and blue[x][j + 1] == 0:
                pre = j
                j += 1
            else:
                break
        blue[x][pre] = 1
        blue[x][pre + 1] = 1
        i = 0
        pre = 0
        while i < 6:
            if green[i][y] == 0 and green[i][y + 1] == 0:
                pre = i
                i += 1
            else:
                break
        green[pre][y] = 1
        green[pre][y + 1] = 1
    else:
        j = 0
        pre = 0
        while j < 6:
            if blue[x][j] == 0 and blue[x + 1][j] == 0:
                pre = j
                j += 1
            else:
                break
        blue[x][pre] = 1
        blue[x + 1][pre] = 1

        i = 0
        pre = 0
        while i < 5:
            if green[i][y] == 0 and green[i + 1][y] == 0:
                pre = i
                i += 1
            else:
                break
        green[pre][y] = 1
        green[pre + 1][y] = 1

# ์ ์ˆ˜ ๊ณ„์‚ฐ ํ›„ ๋ธ”๋Ÿญ ์กฐ์ •
def cal_score():
    global score
    #  blue
    j = 5
    while j > 1:
        count = 0
        for i in range(4):
            if blue[i][j] == 1:
                count += 1
        if count == 4:
            score += 1
            for y in range(j, -1, -1):
                for x in range(4):
                    if y == 0:
                        blue[x][0] = 0
                    else:
                        blue[x][y] = blue[x][y - 1]
        else:
            j -= 1

    # green
    i = 5
    while i > 1:
        count = 0
        for j in range(4):
            if green[i][j] == 1:
                count += 1
        if count == 4:
            score += 1
            for x in range(i, -1, -1):
                for y in range(4):
                    if x == 0:
                        green[0][y] = 0
                    else:
                        green[x][y] = green[x - 1][y]
        else:
            i -= 1

# ํŠน์ˆ˜ ๋ธ”๋Ÿญ ์ฒ˜๋ฆฌ
def special_area():
    # blue
    count = 0
    for j in range(2):
        for i in range(4):
            if blue[i][j] == 1:
                count += 1
                break

    while count != 0:
        sy = 6 - count
        while sy != 0:
            for i in range(4):
                blue[i][sy] = blue[i][sy - 1]
            sy -= 1
        for i in range(4):
            blue[i][0] = 0
        count -= 1
    # red
    count = 0
    for i in range(2):
        for j in range(4):
            if green[i][j] == 1:
                count += 1
                break

    while count != 0:
        sx = 6 - count
        while sx != 0:
            for j in range(4):
                green[sx][j] = green[sx - 1][j]
            sx -= 1
        for j in range(4):
            green[0][j] = 0
        count -= 1


# solution
for _ in range(N):
    t, x, y = map(int, input().split())
    fill_block(t, x, y)
    cal_score()
    special_area()

val = 0
for row in blue:
    val += row.count(1)

for row in green:
    val += row.count(1)
print(score)
print(val)