λ¬Έμ
https://www.acmicpc.net/problem/2493
νμ΄
# λ°±μ€ 2493λ² λ¬Έμ - ν
import sys
input = sys.stdin.readline
n = int(input())
tops = list(map(int, input().split()))
answer = [0] * n
stack = []
for i in range(len(tops)):
while stack:
if tops[stack[-1][0]] < tops[i]:
stack.pop()
else:
answer[i] = stack[-1][0] + 1
break
stack.append((i, tops[i]))
print(*answer)
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Python] [Gold3] 1600λ²_λ§μ΄ λκ³ ν μμμ΄ (0) | 2023.03.16 |
---|---|
π© [λ°±μ€] [Python] [Gold4] 17298λ²_μ€ν°μ (1) | 2023.03.15 |
π© [λ°±μ€] [Python] [Silver2] 5397λ²_ν€λ‘κ±° (0) | 2023.03.13 |
π© [λ°±μ€] [Python] [Gold5] 1717λ²_μ§ν©μ νν (0) | 2023.03.10 |
π© [λ°±μ€] [Python] [Silver2] 1406λ²_μλν° (0) | 2023.03.09 |