오등큰수


Define input, output

  • Input:
  • Output:

설명

source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import sys
from collections import Counter

N = int(sys.stdin.readline())
array = list(map(int, sys.stdin.readline().strip().split(" ")))
cnt = Counter(array)
cnt_array = list(map(lambda x: (cnt[x], x), array))

stack = []
answer = [-1] * N
for i, (val, mapping) in enumerate(cnt_array):
    while stack and cnt_array[stack[-1][0]][0] < val:
        j, v, m = stack.pop()
        answer[j] = mapping
    stack.append([i, val, mapping])

print(*answer)
Built with Hugo
Theme Stack designed by Jimmy