run2ai / algorithm-taek

0 stars 0 forks source link

스택으로 오름차순 수열 만들기 #12

Closed Blzae97 closed 2 months ago

Blzae97 commented 2 months ago

시간 제한: 2초 난이도: 실버Ⅲ 백준 온라인 저지: 1874번 https://www.acmicpc.net/problem/1874

teang1995 commented 2 months ago
# https://www.acmicpc.net/problem/1874

import sys

N = int(sys.stdin.readline())

eles = list(reversed([i + 1 for i in range(N)]))
nums = []
temp = []
stack = [] # DEBUGGING
results = []
flag = True

for i in range(N):
    num = int(sys.stdin.readline())
    if temp and temp[-1] == num:
        n = temp.pop()
        results.append("-")
        continue

    elif temp and temp[-1] > num:
        flag = False
        break

    else:
        while True:
            n = eles.pop()
            results.append("+")
            temp.append(n) # DEBUGGING
            if n == num:
                temp.pop()
                results.append("-")
                break

if flag:
    for result in results:
        print(result)

else:
    print("NO")