1. [re] 마법사 상어와 파이어볼

아현·2021년 9월 14일
0

Algorithm

목록 보기
318/400

백준


1. 시뮬레이션



import sys
input = sys.stdin.readline

n, m , k = map(int, input().split())
fireball = []
check = [[[] for _ in range(n)] for _ in range(n)]

for _ in range(m):
    r, c, m, s, d = map(int, input().split())
    fireball.append([r - 1, c - 1, m, s, d])

#0, 1, 2, 3, 4, 5, 6, 7
dx = [-1, -1, 0, 1, 1, 1, 0, -1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

for _ in range(k):
    for x, y, m, s, d in fireball:
        nx = (x + (dx[d] * s)) % n
        ny = (y + (dy[d] * s)) % n
        
        check[nx][ny].append([nx, ny, m, s, d])

    fireball.clear()

    for i in range(n):
        for j in range(n):
            if len(check[i][j]) == 0:
                continue
            elif len(check[i][j]) == 1:
                fireball.append(check[i][j][0])

            else:
                sm, ss, cnt = 0, 0, 0
                odd, even = 0, 0
                for x, y, m, s, d in check[i][j]:
                    sm += m
                    ss += s
                    cnt += 1
                    if d % 2 == 0:
                        even += 1
                    else:
                        odd += 1
                dm = sm // 5
                ds = ss // cnt
                if odd and even:
                    for direction in range(1, 8, 2):
                        fireball.append([i, j, dm, ds, direction])
                else:
                     for direction in range(0, 7, 2):
                            fireball.append([i, j, dm, ds, direction])
            
            check[i][j].clear()

total = 0
for x, y, m, s, d in fireball:
    total += m

print(total)
                
                

                
                


profile
For the sake of someone who studies computer science

0개의 댓글