Skip to content

(22 ๋ณต์Šต) ์‚ผ์„ฑ SW ์—ญ๋Ÿ‰ ํ…Œ์ŠคํŠธ ๊ธฐ์ถœ ๋ฌธ์ œ / ๋ฐฑ์ค€ / 20056๋ฒˆ : ๋งˆ๋ฒ•์‚ฌ ์ƒ์–ด์™€ ํŒŒ์ด์–ด๋ณผ: ๊ฒฉ์ž์˜ ํ–‰๊ณผ ์—ด์€ 1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€ ๋ฒˆํ˜ธ๊ฐ€ ๋งค๊ฒจ์ ธ ์žˆ๊ณ , 1๋ฒˆ ํ–‰์€ N๋ฒˆ๊ณผ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๊ณ , 1๋ฒˆ ์—ด์€ N๋ฒˆ ์—ด๊ณผ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค.ย #143

@sallyy1

Description

@sallyy1

image

๊ฒฉ์ž์˜ ํ–‰๊ณผ ์—ด์€ 1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€ ๋ฒˆํ˜ธ๊ฐ€ ๋งค๊ฒจ์ ธ ์žˆ๊ณ , 1๋ฒˆ ํ–‰์€ N๋ฒˆ๊ณผ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๊ณ , 1๋ฒˆ ์—ด์€ N๋ฒˆ ์—ด๊ณผ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค.

nx = (nx + N) % N, ny = (ny + N) % N

nx, ny = r + (dx[d]*s), c + (dy[d]*s)
nx = (nx + n) % n ###
ny = (ny + n) % n ###
  • (์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์ž˜ ํ™œ์šฉํ•˜๋ฉด, a[i][j] ๋ฐฐ์—ด ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๋ฌธ์ œ์—์„œ ์ฃผ์–ด์ง„ ํŒŒ์ด์–ด๋ณผ์˜ ์ •๋ณด ๋ฆฌ์ŠคํŠธ๋งŒ ๊ฐ€์ง€๊ณ  ํ’€ ์ˆ˜ ์žˆ์Œ)
  • ์ด๋ฒˆ์—๋Š” ์ˆ˜ํ–‰ ํ›„ ํŒŒ์ด์–ด๋ณผ์˜ ์ •๋ณด๋ฅผ Dictionary์— ์ €์žฅํ•ด๋ด„

dx = [-1,-1,0,1,1,1,0,-1]
dy = [0,1,1,1,0,-1,-1,-1]


# ์ž…๋ ฅ
n, m, k = map(int, input().split())

before_fireballs = [list(map(int, input().split())) for _ in range(m)]
# [ํ–‰, ์—ด, ์งˆ๋Ÿ‰, ์†๋ ฅ, ๋ฐฉํ–ฅ] + ํŒŒ์ด์–ด๋ณผ idx
# [0,  1,  2,   3,   4] + 5


## ๋งค ํ„ด๋งˆ๋‹ค -> ํ•ฉ์ณ์ง€๋Š” ํŒŒ์ด์–ด๋ณผ์˜ ์ •๋ณด๋ฅผ ์ž„์‹œ๋กœ ์ €์žฅํ•  ๋ฐฐ์—ด์ด ํ•„์š”ํ•จ..
## ์งˆ๋Ÿ‰์ด 0์ธ ํŒŒ์ด์–ด๋ณผ์€ ์†Œ๋ฉธ๋˜์–ด ์—†์–ด์ง„๋‹ค => ๋‹ค์Œ ํ„ด์—์„œ๋Š” ๊ฒŒ์ž„์ˆ˜ํ–‰ ๋Œ€์ƒ์ด ์•ˆ ๋จ !!!


for turn in range(k):
    result = dict()
    fireballs = []

    # 1 ๋‹จ๊ณ„. ๋ชจ๋“  ํŒŒ์ด์–ด๋ณผ์˜ ์ด๋™
    for idx in range(len(before_fireballs)):
        r, c, m, s, d = before_fireballs[idx]
        ####print(r, c)

        if m == 0: ## (์˜ˆ์™ธ ์ฒ˜๋ฆฌ : ์ด์ „ ํ„ด์—์„œ ์†Œ๋ฉธ๋œ ํŒŒ์ด์–ด๋ณผ์€ pass)
            continue

        nx, ny = r + (dx[d]*s), c + (dy[d]*s)
        nx = (nx + n) % n ###
        ny = (ny + n) % n ###

        result.setdefault((nx, ny),  [])
        result[(nx, ny)].append([m, s, d, idx])
                                # 0, 1, 2, 3

    ###print(result)

    # 2 ๋‹จ๊ณ„. (2๊ฐœ ์ด์ƒ์˜ ํŒŒ์ด์–ด๋ณผ์ด ์žˆ๋Š” ์นธ์—์„œ๋Š”) ํŒŒ์ด์–ด๋ณผ์˜ ํ•ฉ์ณ์ง + ๋‚˜๋ˆ ์ง + ์†Œ๋ฉธ
    for key, value in result.items():
        ###print(key)
        ###print(value)
        new_i, new_j = key
        fire_lt = value

        if len(fire_lt) == 1:
            mm, ss, dd, idx = fire_lt[0]
            fireballs.append([new_i, new_j, mm, ss, dd])
            ################# 0,  1,  2,  3,  4
            # fireballs[idx][0] = i
            # fireballs[idx][1] = j ### ์ด๋™ํ•œ ์œ„์น˜ ์ •๋ณด๋กœ ์—…๋ฐ์ดํŠธ
            continue


        m_sum = 0
        s_sum = 0
        for elem in fire_lt:
            mm, ss, dd, idx = elem
            m_sum += mm
            s_sum += ss

        new_m = m_sum // 5
        new_s = s_sum // len(fire_lt)


        # (์งˆ๋Ÿ‰์ด 0์ธ ํŒŒ์ด์–ด๋ณผ์€ ์†Œ๋ฉธ๋˜์–ด ์—†์–ด์ง„๋‹ค.)
        if new_m == 0:
            continue

        # 4๊ฐœ์˜ ํŒŒ์ด์–ด๋ณผ๋กœ ํ์–ด๋œจ๋ฆฌ๊ธฐ
        ### 1) ๋ชจ๋‘ ํ™€์ˆ˜ ์ด๊ฑฐ๋‚˜ 2) ๋ชจ๋‘ ์ง์ˆ˜์ด๋ฉด
        if all( (elem[2]%2 == 1)  for elem in fire_lt) == True or all( (elem[2]%2 == 0) for elem in fire_lt) == True:
            for new_d in [0, 2, 4, 6]:
                fireballs.append([new_i, new_j, new_m, new_s, new_d])

        else:
            for new_d in [1, 3, 5, 7]:
                fireballs.append([new_i, new_j, new_m, new_s, new_d])



    before_fireballs = fireballs[:] # ๋ฐฐ์—ด ์ •๋ณด ์—…๋ฐ์ดํŠธ



# ๋‚จ์•„ ์žˆ๋Š” ํŒŒ์ด์–ด๋ณผ์˜ ์งˆ๋Ÿ‰์˜ ํ•ฉ ๊ณ„์‚ฐ
score = 0
for elem in fireballs:
    score += elem[2]

print(score)


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions