무제
[백준] 17299번 오등큰수 본문
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를 사용할 수 있으면 쉽게 적용할 수 있는 문제였다
'Study > Coding Test 오답노트' 카테고리의 다른 글
| [백준] 6588번 골드바흐의 추측 (0) | 2024.11.27 |
|---|---|
| [백준] 10820 문자열 분석 / 1463 1로 만들기 (0) | 2024.11.26 |
| [백준] 10799번 쇠막대기 (2) | 2024.11.13 |
| [백준] 17413번 단어뒤집기 2 (0) | 2024.11.12 |
| [백준] 1158번 요세푸스 문제 (0) | 2024.11.10 |
Comments