알고리즘 문제풀이

도키도키 간식드리미[백준 12789]

wiojfe 2024. 7. 11. 20:30

설명이 좀 어려워서 처음에 이해가 어려웠다. 

하지만 스택을 사용하면 어렵지 않게 해결이 가능하다. 

https://www.acmicpc.net/problem/12789

 

n =int(input())
arr =list(map(int,input().split()))
stack = []
now = 1
for i in range(len(arr)):
    stack.append(arr[i])
    while stack and stack[-1]== now :
        stack.pop() 
        now += 1 
print('Sad' if stack else 'Nice')