[アルゴリズム]白駿-1874(スタック数列)/PISUN

3074 ワード

import sys

N = int(input())
highest = 1
answer = ''
stack = []
check = False
for i in range(N):
    num = int(sys.stdin.readline())
    while highest <= num:
        stack.append(highest)
        answer += '+\n'
        highest+=1
    if stack[-1] == num:
        stack.pop()
        answer += '-\n'
    else:
        check = True

if check:
    print('NO')
else :
    print (answer)

時間差これは何ですか...