DevYoon
[λ°±μ€] 20056. λ§λ²μ¬ μμ΄μ νμ΄μ΄λ³Ό (Python) λ³Έλ¬Έ
link π https://www.acmicpc.net/problem/20056
π¦ νμ΄μ΄λ³Όμ λͺ¨λ ν©μ³ λλ λ, 0μ΄λ©΄ μλ©Έλλ€λ 쑰건μ μ μ©νμ§ μμμ λ΅μ΄ νλμ μ λμμλ€.
π¦ νμμ λ¬λ¦¬ 2μ°¨μ board 리μ€νΈλ₯Ό μμ±ν λ 0μ΄ μλ []μΌλ‘ μμ±ν΄μ€¬λλ°, μ΄λ₯Ό κ³ λ €νμ§ μμμ μΈλ±μ€ μλ¬κ° λμμλ€.
import sys
input = sys.stdin.readline
dir = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def cal(y, x):
length = len(board[y][x])
tempM = 0
tempS = 0
tempOdd = 0 # λ°©ν₯μ΄ νμμΌ λ
tempEven = 0 # λ°©ν₯μ΄ μ§μμΌ λ
for m, s, d in board[y][x]:
tempM += m # μ§λ λνκΈ°
tempS += s # μλ ₯ λνκΈ°
if d % 2: # λ°©ν₯μ΄ μ§μμΈμ§ νμμΈμ§ ꡬλΆ
tempOdd += 1
else:
tempEven += 1
tempM //= 5
tempS //= length
if tempOdd == length or tempEven == length: # λ°©ν₯μ΄ λͺ¨λ μ§μμ΄κ±°λ λͺ¨λ νμμ΄κ±°λ
changeDir = [0, 2, 4, 6]
else:
changeDir = [1, 3, 5, 7]
if tempM: # μ§λμ΄ 0μΈ νμ΄μ΄λ³Όμ μλ©Έμ΄λ―λ‘
for cd in changeDir: # λ°©ν₯ μμΌλ‘
fireball.append([y, x, tempM, tempS, cd]) # νμ΄μ΄λ³Ό μΆκ°
board[y][x] = [] # μλ μΉΈ μ΄κΈ°ν
def moveFireball(fb):
y, x, m, s, d = fb
my = (y+dir[d][0]*s)%N # y μ΄λ, μ²μκ³Ό λ μ°κ²°
mx = (x + dir[d][1] * s) % N # x μ΄λ, μ²μκ³Ό λ μ°κ²°
board[my][mx].append([m, s, d]) # μΉΈμ μ½μ
N, M, K = map(int, input().split())
board = [[[] for _ in range(N)] for _ in range(N)]
fireball = []
res = 0
for _ in range(M):
y, x, m, s, d = map(int, input().split()) # y, x, μ§λ, μλ ₯, λ°©ν₯
fireball.append([y-1, x-1, m, s, d])
for _ in range(K):
# νμ΄μ΄λ³Ό μ΄λ
while fireball:
fb = fireball.pop(0)
moveFireball(fb)
# μ΄λμ΄ λλ ν
for y in range(N):
for x in range(N):
if len(board[y][x]) >= 2:
cal(y, x)
elif len(board[y][x]) == 1:
m, s, d = board[y][x][0]
fireball.append([y, x, m, s, d])
board[y][x] = []
for fb in fireball:
res += fb[2]
print(res)