๐ 20061 : ๋ชจ๋ ธ๋ฏธ๋ ธ๋๋ฏธ๋ ธ 2 ๐
๐ค ๋ฌธ์ ํ์ด ๐ค
"๊ตฌํ"๊ณผ "์๋ฎฌ๋ ์ด์ "์ ํธ๋ ๋ฐฉ๋ฒ์ ์์ ๊ฐ์ธ ๊ฒ ๊ฐ๋ค. ๋ฌธ์ ์กฐ๊ฑด์ด ๊ต์ฅํ ๋ณต์กํ๊ณ ๊ตฌํํ์๋ ๊ท์ฐฎ์ ๋ถ๋ถ๋ค์ด ๋ง์ด ๋ณด์ด๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ํ์ด๋ฅผ ํ๊ธฐ ์ซ์ด์ง๊ฒ ๋๋ค.
ํ์ง๋ง ์ด๋ฐ ๊ตฌํ ๋ฌธ์ ๋ฅผ ๋ง์ด ํ๋ค๋ณด๋ฉด ๊ตฌํ์ ๋ํด ๋๋ ค์์ด ์ฌ๋ผ์ ธ์ ์ฌ๋ฌ๊ฐ์ง ์๋๋ฅผ ์ฝ๊ฒ ํด๋ณผ ์ ์๋ ๊ฒ ๊ฐ๋ค.
์ด ๋ฌธ์ ์์ ์ด๋ ค์ ๋ ์ ์
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)
'๐ช๐ป์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[DP] ๋ฐฑ์ค 11058 ํฌ๋ฆฌ๋ณด๋ python (0) | 2021.04.03 |
---|---|
[BFS, ๊ตฌํ] ๋ฐฑ์ค 16236 ์๊ธฐ ์์ด python (0) | 2021.04.01 |
[DP] ๋ฐฑ์ค 1699 ์ ๊ณฑ์์ ํฉ python (1) | 2021.04.01 |
[DP] ๋ฐฑ์ค 2133 ํ์ผ์ฑ์ฐ๊ธฐ python (0) | 2021.04.01 |