백준1874

김성민·2023년 11월 21일

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class Solution {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        ArrayList<Character> out = new ArrayList<>();
        int index = 0;
        //4,3,6,8,7,5,2,1 ok
        //5,1,2,5,3,4 no
        //5,4,2,3,1,5 no
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();

        }
        for (int j = 1; j <= N; j++) {
            stack.push(j);
            out.add('+');
            while (!stack.empty() && stack.peek() == arr[index]) {
                stack.pop();
                out.add('-');
                index++;
            }
        }

        if (stack.empty()) {
            for (Character c : out) System.out.println(c);
        } else{
            System.out.println("NO");
        }
    }
}

0개의 댓글