From 150e44ef505e261a1d98c277b65b27c2150ff99d Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 6 Jul 2026 13:40:28 +0900 Subject: [PATCH] =?UTF-8?q?3015=20:=20=EC=98=A4=EC=95=84=EC=8B=9C=EC=8A=A4?= =?UTF-8?q?=20=EC=9E=AC=EA=B2=B0=ED=95=A9=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week4/BOJ3015/BOJ3015_V1.cpp | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/week4/BOJ3015/BOJ3015_V1.cpp diff --git a/src/week4/BOJ3015/BOJ3015_V1.cpp b/src/week4/BOJ3015/BOJ3015_V1.cpp new file mode 100644 index 0000000..641b340 --- /dev/null +++ b/src/week4/BOJ3015/BOJ3015_V1.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; +int n; +long long int ret, temp; +stack> s; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> n; + + for (int i = 0; i < n; i++) { + cin >> temp; + int cnt = 1; + while (s.size() && s.top().first <= temp) { + ret += s.top().second; + if (s.top().first == temp) { + cnt = s.top().second + 1; + } else { + cnt = 1; + } + s.pop(); + } + + if (s.size()) ret++; + s.push({temp,cnt}); + } + + cout << ret << '\n'; + return 0; +} \ No newline at end of file