๐ ๋ฌธ์
https://www.acmicpc.net/problem/20546
๐ ํ์ด
1. 1์ 14์ผ์ ์์ฐ์ (ํ๊ธ + 1์ 14์ผ์ ์ฃผ๊ฐ × ์ฃผ์ ์)๋ก ๊ณ์ฐ
-> ์คํ, ์ฑ๋ฏผ์ด์ ์์ฌ ํ๊ธ, ์ฃผ์ ์ ๋ณ์ ๊ฐ๊ฐ ํ์
-> 1์ 14์ผ์ ์ฃผ๊ฐ: stock[-1] ๋ก ๊ตฌํ
๐ป ๋ด ์ฝ๋
n = int(input())
stock = list(map(int, input().split()))
last = len(stock)
jun = 0
seong = 0
for i in range(last):
# q๋ ์ฃผ์ ์
q = n // stock[i]
if q > 0 :
# ์คํ ์ฃผ์ ์คํ์ผ
n -= q * stock[i]
jun = n + q * stock[last-1]
# ์ฑ๋ฏผ ์ฃผ์ ์คํ์ผ
if stock[i] > stock[i+1] and stock[i+1] > stock[i+2]:
n -= q * stock[i+2]
seong = n + q * stock[i+2]
elif stock[i] < stock[i+1] and stock[i+1] < stock[i+2]:
n += q * stock[i+2]
seong = n + q * stock[i+2]
print(jun)
print(seong)
if jun > seong:
print("BNP")
elif jun < seong:
print("TIMING")
elif jun == seong:
print("SAMESAME")
๐ป ๋ต์
n = int(input())
stock = list(map(int, input().split()))
# ์คํ๊ณผ ์ฑ๋ฏผ์ ์ด๊ธฐ ํ๊ธ ๋ฐ ์ฃผ์ ๋ณด์ ์ํ
# jun_cash: ์คํ์ด ๋ณด์ ํ๊ธ
# jun_stock : ์คํ ๋ณด์ ์ฃผ์ ๊ฐ์
jun_cash = n
jun_stock = 0
seong_cash = n
seong_stock = 0
# ์ฃผ์ ๊ฐ๊ฒฉ ๋ณํ ์ฒ๋ฆฌ
for i in range(len(stock)):
# ์คํ: ๊ฐ์ง ๋์ผ๋ก ์ต๋ ์ฃผ์ ๊ตฌ๋งค
if jun_cash >= stock[i]:
jun_stock += jun_cash // stock[i]
jun_cash %= stock[i]
# ์ฑ๋ฏผ: 3์ผ ์ฐ์ ์์น/ํ๋ฝ ํ์ธ ๋ฐ ๋งค๋งค
if i >= 3:
# 3์ผ ์ฐ์ ํ๋ฝ -> ์ ๋ ๋งค์
if stock[i - 3] > stock[i - 2] > stock[i - 1] > stock[i]:
seong_stock += seong_cash // stock[i]
seong_cash %= stock[i]
# 3์ผ ์ฐ์ ์์น -> ์ ๋ ๋งค๋
elif stock[i - 3] < stock[i - 2] < stock[i - 1] < stock[i]:
seong_cash += seong_stock * stock[i]
seong_stock = 0
# ๋ง์ง๋ง ๋ ์์ฐ ๊ณ์ฐ
jun_total = jun_cash + jun_stock * stock[-1]
seong_total = seong_cash + seong_stock * stock[-1]
# ๊ฒฐ๊ณผ ์ถ๋ ฅ
if jun_total > seong_total:
print("BNP")
elif jun_total < seong_total:
print("TIMING")
else:
print("SAMESAME")
๐ ์ฐธ๊ณ ์๋ฃ
โบ๏ธ ์๋ก ์๊ฒ ๋ ์ง์
1. 3์ผ ์ฐ์ ์์น/ ํ๋ฝ ๊ตฌํํ ๋
์งํผํฐ์์ ์๋ ์ฒ๋ผ ์๋ ค์ค.
๋จ์ํ๊ฒ ์ด๋ ๊ฒ ๊ตฌํํ ์ ๋ ์์
if i >= 3:
# 3์ผ ์ฐ์ ํ๋ฝ -> ์ ๋ ๋งค์
if stock[i - 3] > stock[i - 2] > stock[i - 1] > stock[i]:
seong_stock += seong_cash // stock[i]
seong_cash %= stock[i]
# 3์ผ ์ฐ์ ์์น -> ์ ๋ ๋งค๋
elif stock[i - 3] < stock[i - 2] < stock[i - 1] < stock[i]:
seong_cash += seong_stock * stock[i]
seong_stock = 0
๐ ๋ฆฌ๋ทฐ
'Algorithm > Implement' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค/ ๋ชจ์์ฌ์ (0) | 2024.12.28 |
---|---|
7568๋ฒ / ๋ฉ์น (0) | 2024.12.28 |
๊ตฌํ/ 21918๋ฒ/ ์ ๊ตฌ (0) | 2024.12.25 |
๊ตฌํ/14467๋ฒ/์๊ฐ ๊ธธ์ ๊ฑด๋๊ฐ ์ด์ 1 (0) | 2024.12.24 |
[ํ๋ก๊ทธ๋๋จธ์ค] Level2/ ์คํฌํธ๋ฆฌ (0) | 2024.11.01 |