무제

[백준] 17299번 오등큰수 본문

Study/Coding Test 오답노트

[백준] 17299번 오등큰수

mugan1 2024. 11. 22. 21:16
import sys
input = sys.stdin.readline
from collections import Counter

n = int(sys.stdin.readline())
n_list = list(map(int, sys.stdin.readline().split()))
n_counter = Counter(n_list)

ngf= [-1]*n
stack = [0]
for i in range(1, n):
    while stack and n_counter[n_list[stack[-1]]] < n_counter[n_list[i]]:
        ngf[stack.pop()] = n_list[i]
    stack.append(i)
print(*ngf)

 

오큰수에서 Counter를 사용할 수 있으면 쉽게 적용할 수 있는 문제였다

Comments