File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ 처음 생각
3+ import sys
4+ N = int(sys.stdin.readline().strip())
5+ tops = list(map(int, sys.stdin.readline().split()))
6+ tops = list(reversed(tops))
7+ answer = []
8+ # i는 0부터 3까지
9+ for i in range(N - 1):
10+ # j는 1부터 4까지
11+ for j in range(i+1, N):
12+ if tops[i] > max(tops[j:]):
13+ answer.append(N)
14+ elif tops[i] <= tops[j]:
15+ answer.append(tops[j])
16+ answer.append(N)
17+ reversed_tops = [N - x for x in answer]
18+ print(list(reversed(reversed_tops)))
19+ """
20+
21+ import sys
22+
23+ N = int (sys .stdin .readline ().strip ())
24+ heights = list (map (int , sys .stdin .readline ().split ()))
25+
26+ result = [0 ] * N
27+
28+ stack = []
29+
30+ for i in range (N ):
31+ height = heights [i ]
32+
33+ while stack and heights [stack [- 1 ]] < height :
34+ stack .pop ()
35+
36+ if stack :
37+ result [i ] = stack [- 1 ] + 1
38+
39+ stack .append (i )
40+
41+ print (' ' .join (map (str , result )))
You can’t perform that action at this time.
0 commit comments