1 10828 ์Šคํƒ ์„ฑ๊ณต 41369 108817 38.494%
์Šคํƒ์˜ ๊ฐœ๋…์„ ์ตํžˆ๊ณ  ์‹ค์Šตํ•˜๋Š” ๋ฌธ์ œ

def push(num):
    arrayList.append(num)

def pop() :
    if len(arrayList) == 0 :
        print(-1)
    else :
        print(arrayList.pop())

def size() :
    print(len(arrayList))

def empty() :
    if len(arrayList) == 0 :
        print(1)
    else :
        print(0)

def top() :
    if len(arrayList) == 0 :
        print(-1)
    else :
        print(arrayList[-1])

import sys

arrayList = []
T = int(input())
for i in range(T) :
    # a, b = list(map(str, input().split()))
    N = sys.stdin.readline().rstrip().split()
    a = N[0]
    if a == "push" :
        push(N[1])
    elif a == "pop" :
        pop()
    elif a == "size" :
        size()
    elif a == "empty" :
        empty()
    elif a == "top" :
        top()

2 10773 ์ œ๋กœ ์„ฑ๊ณต์ถœ์ฒ˜๋‹ค๊ตญ์–ด 17259 25888 67.809%
๊ฐ€์žฅ ์ตœ๊ทผ์— ์“ด ์ˆ˜๋ฅผ ์ง€์šฐ๋Š” ๋ฌธ์ œ

arrayList = []

def puts(num) :
    arrayList.append(num)

def pops() :
    arrayList.pop()

T = int(input())
for i in range(T):
    number = int(input())
    if number != 0 :
        puts(number)
    else :
        pops()

    if i == T-1:
        print(sum(arrayList))

3 9012 ๊ด„ํ˜ธ ์„ฑ๊ณต์ถœ์ฒ˜๋‹ค๊ตญ์–ด 38311 87721 42.490%
์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์ด ์˜ฌ๋ฐ”๋ฅธ ๊ด„ํ˜ธ์—ด์ธ์ง€ ํŒ๋‹จํ•˜๋Š” ๋ฌธ์ œ

t = int(input())
for i in range(t) :
    case = input()
    b = list(case)
    sum = 0
    for j in b :
        if j == '(' :
            sum += 1
        elif j == ')' :
            sum -= 1
        if sum < 0:
            print('NO')
            break
    if sum > 0:
        print('NO')
    elif sum == 0:
        print('YES')

4 4949 ๊ท ํ˜•์žกํžŒ ์„ธ์ƒ ์„ฑ๊ณต์ถœ์ฒ˜๋‹ค๊ตญ์–ด 11168 33926 32.720%
์œ„์™€ ๊ฐ™์€๋ฐ ๊ด„ํ˜ธ์˜ ์ข…๋ฅ˜๊ฐ€ ๋‹ค์–‘ํ•ด์ง„ ๋ฌธ์ œ

while True :
    x = input()
    if x == '.' : 
        break
    list = []
    tf = True
    for i in x :
        if i == '[' or i == '(' :
            list.append(i)

        elif i == ']' :
            if len(list) == 0 or list[-1] != '[':
                tf = False
                break
            list.pop(-1)
        elif i == ')' :
            if len(list) == 0 or list[-1] != '(':
                tf = False
                break
            list.pop(-1)
    if tf and len(list) ==0: 
        print("yes")
    else : 
        print("no")

5 1874 ์Šคํƒ ์ˆ˜์—ด ์„ฑ๊ณต 20456 59058 34.340%
์Šคํƒ์„ ํ™œ์šฉํ•˜๋Š” ๋ฌธ์ œ

s = []
outputList = []
temp = True

count = 1
for i in range(int(input())):
    num = int(input())
    while count <= num:
        s.append(count)
        outputList.append('+')
        count += 1
    if s[-1] == num:
        s.pop()
        outputList.append('-')
    else:
        temp = False
        
if temp == False:
    print('NO')
else:
    for i in outputList:
        print(i)

6 17298 ์˜คํฐ์ˆ˜ ์„ฑ๊ณต 6139 17993 34.183%
์Šคํƒ์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” ๊ฝค ์–ด๋ ค์šด ๋ฌธ์ œ

import sys

n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
stack = []
answer = [-1 for i in range(n)]

for i in range(len(arr)):
    while stack and arr[stack[-1]] < arr[i]:
        answer[stack.pop()] = arr[i]
    stack.append(i)
print(*answer)

#์ฒ˜์Œ์— ์•„๋ž˜์ฒ˜๋Ÿผํ•ด์„œ ์‹œ๊ฐ„์ดˆ๊ณผ๋‚จ
# import sys

# t = int(sys.stdin.readline())
# list = list(map(int, sys.stdin.readline().split()))

# for i in range(t) :
#     list02 = list[:]
#     point = list02[i]
#     temp = -1
#     while True : 
#         popNum = list02.pop()
#         if popNum > point :
#             temp = popNum
#         elif point == popNum :
#             break
#     print(temp, end=" ")
728x90
๋ฐ˜์‘ํ˜•
Liky