본문 바로가기

코테

생명과학부 랩 인턴

728x90
반응형
SMALL

단순 시뮬레이션이다 보니 생각보니 오래 걸리지 않았습니다.

 

import sys

n, m, k = map(int, sys.stdin.readline().strip().split())

graph = [[ [] for _ in range(m) ] for _ in range(n) ]
g_infos = []
dx, dy = [0, 0, 1, -1], [-1, 1, 0, 0]
answer = 0

for _ in range(k):
    x, y, s, d, b = map(int, sys.stdin.readline().strip().split())
    graph[x - 1][y - 1].append([s, d - 1, b])
    g_infos.append([x - 1, y - 1, s, d - 1, b])

def fight_g():
    global graph, n, m, g_infos
    for y in range(n):
        for x in range(m):
            if len(graph[y][x]) >= 2:
                graph[y][x].sort(key = lambda x: -x[2])
                for i in range(len(graph[y][x])):
                    if i != 0:
                        s, d, b = graph[y][x][i]
                        g_infos.remove([y, x, s, d, b])
                graph[y][x] = [graph[y][x][0]]
def validation(ny, nx):
    global n, m
    if ny >= n or ny < 0 or nx >= m or nx < 0:
        return False
    return True

def move_g(info):
    global graph, dx, dy

    y, x, s, d, b = info
    graph[y][x].remove([s, d, b])
    turn = s
    while turn:
        nx = x + dx[d]
        ny = y + dy[d]
        if validation(ny, nx):
            y, x = ny, nx
            turn -= 1
        else: #칸을 넘었을 때
            if d == 0:
                d = 1
            elif d == 1:
                d = 0
            elif d == 2:
                d = 3
            elif d == 3:
                d = 2
    graph[y][x].append([s, d, b])
    return [y, x, s, d, b]

def g_check(f_x):
    global graph, n, m, answer, g_infos
    for y in range(n):
        for x in range(m):
            if f_x == x:
                if len(graph[y][x]) != 0:
                    s, d, b = graph[y][x].pop()
                    g_infos.remove([y, x, s, d, b])
                    answer += b
                    return

for y in range(n):
    for x in range(m):
        continue

for x in range(m):
    g_check(x)
    for i in range(len(g_infos)):
        g_infos[i] = move_g(g_infos[i])

    fight_g()
print(answer)
728x90
반응형
LIST

'코테' 카테고리의 다른 글

14500 - 테트로미노  (1) 2023.03.28
바이러스 검사  (0) 2023.03.28
2개의 사탕  (0) 2023.03.28
시공의 돌풍  (0) 2023.03.28
팩맨  (0) 2023.03.27