ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

20056๋ฒˆ: ๋งˆ๋ฒ•์‚ฌ ์ƒ์–ด์™€ ํŒŒ์ด์–ด๋ณผ

์ฒซ์งธ ์ค„์— N, M, K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์— ํŒŒ์ด์–ด๋ณผ์˜ ์ •๋ณด๊ฐ€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ํŒŒ์ด์–ด๋ณผ์˜ ์ •๋ณด๋Š” ๋‹ค์„ฏ ์ •์ˆ˜ ri, ci, mi, si, di๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ์„œ๋กœ ๋‹ค๋ฅธ ๋‘ ํŒŒ์ด์–ด๋ณผ์˜ ์œ„์น˜

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ์ž…๋ ฅ๊ฐ’์œผ๋กœ ํŒŒ์ด์–ด๋ณผ์˜ ์œ„์น˜ (r, c), ์งˆ๋Ÿ‰(m), ๋ฐฉํ–ฅ(d), ์†๋ ฅ(s)์ด ์ฃผ์–ด์ง„๋‹ค. ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ๋ฌธ์ œ์ด๋ฏ€๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์„ ์ˆœ์ฐจ์ ์œผ๋กœ ์ง„ํ–‰ํ•œ๋‹ค.

 

  • ๋ชจ๋“  ํŒŒ์ด์–ด๋ณผ์€ ์ž์‹ ์˜ ๋ฐฉํ–ฅ์œผ๋กœ ์†๋ ฅ๋งŒํผ ์ด๋™ํ•œ๋‹ค.
  • ์ด๋™์„ ๋งˆ์นœ ํ›„, ์ด๋™๋œ ํŒŒ์ด์–ด๋ณผ๋“ค์ด ๊ฐ™์€ ์นธ์— 2๊ฐœ ์ด์ƒ ์žˆ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฒ˜๋ฆฌํ•œ๋‹ค.
    • ํŒŒ์ด์–ด๋ณผ์€ 4๊ฐœ๋กœ ๋‚˜๋ˆ„์–ด์ง„๋‹ค.
    • ๋‚˜๋ˆ„์–ด์ง„ ํŒŒ์ด์–ด๋ณผ์˜ ์งˆ๋Ÿ‰, ์†๋ ฅ, ๋ฐฉํ–ฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
      • ์งˆ๋Ÿ‰์€ `ํ•ฉ์ณ์ง„ ํŒŒ์ด์–ด๋ณผ ์งˆ๋Ÿ‰์˜ ํ•ฉ / 5`์ด๋‹ค.
      • ์†๋ ฅ์€ `ํ•ฉ์ณ์ง„ ํŒŒ์ด์–ด๋ณผ ์†๋ ฅ์˜ ํ•ฉ /  ํ•ฉ์ณ์ง„ ํŒŒ์ด์–ด๋ณผ์˜ ๊ฐœ์ˆ˜`์ด๋‹ค.
      • ํ•ฉ์ณ์ง€๋Š” ํŒŒ์ด์–ด๋ณผ์˜ ๋ฐฉํ–ฅ์ด ๋ชจ๋‘ ํ™€์ˆ˜์ด๊ฑฐ๋‚˜ ๋ชจ๋‘ ์ง์ˆ˜์ด๋ฉด, ๋ฐฉํ–ฅ์€ `0, 2, 4, 6`์ด ๋œ๋‹ค.
        • ์•„๋‹ˆ๋ผ๋ฉด `1, 3, 5, 7`์ด ๋œ๋‹ค.
    • ์งˆ๋Ÿ‰์ด 0์ธ ํŒŒ์ด์–ด๋ณผ์€ ์†Œ๋ฉธ๋˜์–ด ์—†์–ด์ง„๋‹ค.

์œ„์™€ ๊ฐ™์€ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์„ K๋ฒˆ ์ˆ˜ํ–‰ํ•œ ํ›„, ๋‚จ์•„์žˆ๋Š” ํŒŒ์ด์–ด๋ณผ ์งˆ๋Ÿ‰์˜ ํ•ฉ์„ ๊ตฌํ•ด์„œ ์ถœ๋ ฅํ•˜๋ฉด ์ •๋‹ต์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

 

 

์ฝ”๋“œ

from sys import stdin
from copy import deepcopy

X = 0
Y = 1
M = 2
S = 3
D = 4


def move_fire_ball():
    global board

    for idx, info in enumerate(fire_ball):
        dx, dy = dirs[info[D]]
        # ์ž์‹ ์˜ ๋ฐฉํ–ฅ์˜ ์†๋„ ๋งŒํผ ์ด๋™ํ•˜๋ฏ€๋กœ ํ˜„์žฌ ์œ„์น˜ + ๋ฐฉํ–ฅ * ์†๋„
        # ๊ฒฉ์ž์˜ ํ–‰๊ณผ ์—ด์€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ, %๋กœ ์œ„์น˜๋ฅผ ์ฐพ์Œ
        next_x, next_y = (info[X] + dx * info[S]) % n, (info[Y] + dy * info[S]) % n

        if board[next_x][next_y] is None:
            board[next_x][next_y] = [idx]
        else:
            board[next_x][next_y].append(idx)

        info[X], info[Y] = next_x, next_y


def calc_file_ball(temp, fireballs, loc):
    # ์งˆ๋Ÿ‰๊ณผ ์†๋„์˜ ํ•ฉ
    sum_m, sum_s = 0, 0
    even, odd = True, True

    for idx in fireballs:
        sum_m += fire_ball[idx][M]
        sum_s += fire_ball[idx][S]

        if not fire_ball[idx][D] % 2:
            odd = False
        else:
            even = False

    cal_m = sum_m // 5
    cal_s = sum_s // len(fireballs)

    # ์งˆ๋Ÿ‰์ด ์—†๋Š” ๊ฒฝ์šฐ์—๋Š”, ์•„๋ž˜์™€ ๊ฐ™์€ ์—ฐ์‚ฐ์ด ํ•„์š” ์—†์Œ
    if cal_m:
        x, y = loc

        # mp -> multiplier
        for mp in range(4):
            # ํŒŒ์ด์–ด๋ณผ์˜ ๋ฐฉํ–ฅ์ด ๋ชจ๋‘ ์ง์ˆ˜๋‚˜ ํ™€์ˆ˜์ธ ๊ฒฝ์šฐ (0, 2, 4, 6)
            if even or odd:
                temp.append([x, y, cal_m, cal_s, 2 * mp])
            # ์•„๋‹Œ ๊ฒฝ์šฐ (1, 3, 5, 7)
            else:
                temp.append([x, y, cal_m, cal_s, 2 * mp + 1])


def sum_fire_ball():
    global fire_ball
    temp = []

    for x in range(n):
        for y in range(n):
            # ํ•ด๋‹น ์œ„์น˜์— fireball์ด ์—†๋Š” ๊ฒฝ์šฐ
            if board[x][y] is None:
                continue
            # ํ—ค๋”ฉ ์œ„์น˜์— fireball์ด ํ•˜๋‚˜์ธ ๊ฒฝ์šฐ
            elif len(board[x][y]) == 1:
                cur_idx = board[x][y][0]
                temp.append(fire_ball[cur_idx])
            # ํ•ด๋‹น ์œ„์น˜์— fireball์ด ๋‘ ๊ฐœ ์ด์ƒ์ธ ๊ฒฝ์šฐ
            else:
                calc_file_ball(temp, board[x][y], (x, y))
            board[x][y] = None

    fire_ball = deepcopy(temp)


if __name__ == '__main__':
    n, m, k = map(int, stdin.readline().split())

    # 8๋ฐฉํ–ฅ์œผ๋กœ ์ด๋™์ด ํ•„์š”ํ•˜๋ฏ€๋กœ
    dirs = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
    board = [[None] * n for _ in range(n)]
    fire_ball = [None] * m

    for idx in range(m):
        cur_info = list(map(int, stdin.readline().split()))
        cur_info[X] -= 1
        cur_info[Y] -= 1
        fire_ball[idx] = cur_info

    for _ in range(k):
        move_fire_ball()
        sum_fire_ball()

    print(sum(map(lambda x: x[M], fire_ball)))
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€