From 1979b6f908bb38ff775d00c82a1a003ce537a773 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Tue, 16 Sep 2025 23:10:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250916]=20BOJ=20/=20P5=20/=20=EC=98=A4?= =?UTF-8?q?=EC=95=84=EC=8B=9C=EC=8A=A4=20=EC=9E=AC=EA=B2=B0=ED=95=A9=20/?= =?UTF-8?q?=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\236\254\352\262\260\355\225\251.md" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "zinnnn37/202509/16 BOJ P5 \354\230\244\354\225\204\354\213\234\354\212\244 \354\236\254\352\262\260\355\225\251.md" diff --git "a/zinnnn37/202509/16 BOJ P5 \354\230\244\354\225\204\354\213\234\354\212\244 \354\236\254\352\262\260\355\225\251.md" "b/zinnnn37/202509/16 BOJ P5 \354\230\244\354\225\204\354\213\234\354\212\244 \354\236\254\352\262\260\355\225\251.md" new file mode 100644 index 00000000..346ffb2a --- /dev/null +++ "b/zinnnn37/202509/16 BOJ P5 \354\230\244\354\225\204\354\213\234\354\212\244 \354\236\254\352\262\260\355\225\251.md" @@ -0,0 +1,58 @@ +```java +import java.io.*; +import java.util.Stack; + +public class BJ_3015_오아시스_재결합 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + private static int N; + private static long ans; + + private static Stack s; + + private static class Node { + int val; + int cnt; + + Node(int val, int cnt) { + this.val = val; + this.cnt = cnt; + } + } + + public static void main(String[] args) throws IOException { + sol(); + } + + private static void sol() throws IOException { + N = Integer.parseInt(br.readLine()); + s = new Stack<>(); + + ans = 0; + for (int i = 0; i < N; i++) { + int n = Integer.parseInt(br.readLine()); + Node cur = new Node(n, 1); + + while (!s.isEmpty() && s.peek().val <= cur.val) { + Node prev = s.pop(); + + ans += prev.cnt; + if (prev.val == cur.val) { + cur.cnt += prev.cnt; + } + } + if (!s.isEmpty()) { + ans++; + } + s.push(cur); + } + bw.write(ans + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file