From 73d34a84e3cdf33e4bc194445a4af49fcdafed3c Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 26 Jul 2025 16:03:23 +0900 Subject: [PATCH] =?UTF-8?q?[20250726]=20BOJ=20/=20G4=20/=20=EC=98=A4?= =?UTF-8?q?=ED=81=B0=EC=88=98=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\230\244\355\201\260\354\210\230.md" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "lkhyun/202507/26 BOJ G4 \354\230\244\355\201\260\354\210\230.md" diff --git "a/lkhyun/202507/26 BOJ G4 \354\230\244\355\201\260\354\210\230.md" "b/lkhyun/202507/26 BOJ G4 \354\230\244\355\201\260\354\210\230.md" new file mode 100644 index 00000000..b41bfc75 --- /dev/null +++ "b/lkhyun/202507/26 BOJ G4 \354\230\244\355\201\260\354\210\230.md" @@ -0,0 +1,43 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int[] arr; + static int[] NGE; + + public static void main(String[] args) throws Exception { + int N = Integer.parseInt(br.readLine()); + arr = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + if(N == 1){ + bw.write("-1"); + bw.close(); + return; + } + + NGE = new int[N]; + ArrayDeque stk = new ArrayDeque<>(); + stk.push(0); + for (int i = 1; i < N; i++) { + while(!stk.isEmpty() && arr[stk.peek()]