๋ฌธ์
https://www.acmicpc.net/problem/17298
ํ์ด
# ๋ฐฑ์ค 17298๋ฒ ๋ฌธ์ - ์คํฐ์
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
answer = [-1] * n
stack = []
for i in range(n):
while stack and a[stack[-1]] < a[i]:
answer[stack.pop()] = a[i]
stack.append(i)
print(*answer)
stack์ ํ์ฉํ ์๋ฃ๊ตฌ์กฐ ๋ฌธ์ ์ด๋ค. ์ ์ ํ์๋ ํ๊ณผ ๋งค์ฐ ์ ์ฌํ ๋ฌธ์ ์ด๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver4] 10825๋ฒ_๊ตญ์์ (0) | 2023.03.18 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold3] 1600๋ฒ_๋ง์ด ๋๊ณ ํ ์์ญ์ด (0) | 2023.03.16 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 2493๋ฒ_ํ (0) | 2023.03.13 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 5397๋ฒ_ํค๋ก๊ฑฐ (0) | 2023.03.13 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1717๋ฒ_์งํฉ์ ํํ (0) | 2023.03.10 |