๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Coding Test/Algorithms

[SWEA] 1225.์•”ํ˜ธ์ƒ์„ฑ๊ธฐ/Python - D3

by The Future Engineer, Lucy 2024. 11. 13.
728x90
๋ฐ˜์‘ํ˜•

โ“๋ฌธ์ œ

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14uWl6AF0CFAYD

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 

์„ฑ๋Šฅ ์š”์•ฝ

list๋ฅผ ํ๋กœ ์‚ฌ์šฉํ•œ ํ’€์ด โžก๏ธ ๋ฉ”๋ชจ๋ฆฌ: 48,136 KB, ์‹œ๊ฐ„: 119 ms, ์ฝ”๋“œ๊ธธ์ด: 357 Bytes
75๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€ ๊ฐ’์—์„œ ๊ณ„์‚ฐํ•œ ํ’€์ด โžก๏ธ ๋ฉ”๋ชจ๋ฆฌ: 43,780 KB, ์‹œ๊ฐ„: 126 ms, ์ฝ”๋“œ๊ธธ์ด: 404 Bytes
deque๋ฅผ ์‚ฌ์šฉํ•œ ํ’€์ด โžก๏ธ ๋ฉ”๋ชจ๋ฆฌ: 48,248 KB, ์‹œ๊ฐ„: 152 ms, ์ฝ”๋“œ๊ธธ์ด: 411 Bytes

โœ๐Ÿปํ’€์ด

ํ๋ฅผ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค.

๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๊ฐ’์„ ๋นผ์ฃผ๋ฉด ๋œ๋‹ค. ๋งจ ์ฒ˜์Œ์— 1์„ ๋นผ์ฃผ๊ณ  ๋’ค๋กœ ๋ณด๋‚ด๊ณ , 2 ๋นผ์ฃผ๊ณ  ๋’ค๋กœ ๋ณด๋‚ด๊ณ ๋ฅผ ๋ฐ˜๋ณตํ•˜๋ฉด 5๋นผ์ฃผ๊ณ  ๋’ค๋กœ ๋ณด๋‚ด๋ฉด ํ•œ ์‚ฌ์ดํด์ด ๋๋‚œ๋‹ค. ๊ทธ๋Ÿผ ๋‹ค์‹œ 1์„ ๋นผ์ฃผ๊ณ  ๋’ค๋กœ ๋ณด๋‚ด๊ณ  2๋ฅผ ๋นผ์ฃผ๊ณ  ๋’ค๋กœ ๋ณด๋‚ด๊ณ ๋ฅผ ๋ฐ˜๋ณตํ•˜๋ฉด ๋œ๋‹ค.

๐Ÿ’ป์ฝ”๋“œ

# list๋ฅผ ํ๋กœ ์‚ฌ์šฉํ•œ ํ’€์ด
for i in range(10):
    t = int(input())
    codes = list(map(int, input().split()))

    sub = 1
    while True:
        if sub > 5:
            sub = 1
        cur = codes.pop(0) - sub
        if cur <= 0:
            codes.append(0)
            break
        codes.append(cur)
        sub += 1


    print("#{} {} {} {} {} {} {} {} {}".format(t, *codes))
# 5๋ฒˆ์ด ํ•œ ์‚ฌ์ดํด๋กœ 15๋งŒํผ ์ฃผ๋Š” ๊ฒฝ์šฐ, 75๋กœ ๋‚˜๋ˆด์„ ๋•Œ ๋‚˜๋ˆˆ ๊ฐ’์—์„œ ๋‚˜๋จธ์ง€ ๊ฐ’ ๊ณ„์‚ฐ.
for i in range(10):
    t = int(input())
    codes = list(map(int, input().split()))

    for i in range(8):
        codes[i] %= 75

    sub = 1
    while True:
        if sub > 5:
            sub = 1
        cur = codes.pop(0) - sub
        if cur <= 0:
            codes.append(0)
            break
        codes.append(cur)
        sub += 1


    print("#{} {} {} {} {} {} {} {} {}".format(t, *codes))
# deque๋ฅผ ์‚ฌ์šฉํ•œ ํ’€์ด
from collections import deque

for i in range(10):
    t = int(input())
    codes = deque(list(map(int, input().split())))

    sub = 1
    while True:
        if sub > 5:
            sub = 1
        cur = codes.popleft()
        cur -= sub
        if cur <= 0:
            codes.append(0)
            break
        codes.append(cur)
        sub += 1


    print("#{} {} {} {} {} {} {} {} {}".format(t, *codes))

๐Ÿ“ํ›„๊ธฐ

์ฒ˜์Œ์—๋Š” ์ผ์ผํžˆ ๊ณ„์‚ฐํ•˜๋ฉด ์‹œ๊ฐ„์ด ๋” ์˜ค๋ž˜ ๊ฑธ๋ฆฌ์ง€ ์•Š์„๊นŒ๋ผ๋Š” ์ƒ๊ฐ์— 5๋ฒˆ ์›€์ง์ด๋ฉด ํ•œ ์‚ฌ์ดํด๋กœ ๋„ํ•ฉ 15๊ฐ€ ๋นผ์ง„๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ณ  75๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€ ๊ฐ’์—์„œ ๊ณ„์‚ฐํ•˜๊ณ ์ž ํ–ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ผ์ผํžˆ ๊ณ„์‚ฐํ•ด์„œ ํ•ด๋„ ์‹œ๊ฐ„์— ๋ณ„ ์ฐจ์ด๊ฐ€ ์—†๋‹ค๋Š” ๊ฒƒ์„ ์•Œ์•˜๋‹ค.

 

728x90
๋ฐ˜์‘ํ˜•