From 7c8e86984878878bf546deb4a6fc0132159a5806 Mon Sep 17 00:00:00 2001 From: InSange Date: Thu, 2 May 2024 00:26:41 +0900 Subject: [PATCH 1/2] =?UTF-8?q?24-05-02=20=EC=98=A4=EC=95=84=EC=8B=9C?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=AC=EA=B2=B0=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InSange/README.md | 1 + "InSange/\354\212\244\355\203\235/3015.cpp" | 62 +++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 "InSange/\354\212\244\355\203\235/3015.cpp" diff --git a/InSange/README.md b/InSange/README.md index bb80ee4..1542bc2 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -11,5 +11,6 @@ | 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] | 8차시 | 2024.04.09 | 투 포인터 | [두 용액](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/32)] | 9차시 | 2024.04.12 | 힙 | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] +| 10차시 | 2024.05.02 | 스택 | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] ======= --- diff --git "a/InSange/\354\212\244\355\203\235/3015.cpp" "b/InSange/\354\212\244\355\203\235/3015.cpp" new file mode 100644 index 0000000..b693d73 --- /dev/null +++ "b/InSange/\354\212\244\355\203\235/3015.cpp" @@ -0,0 +1,62 @@ +#include +#include +#include + +using namespace std; + +long long N, n, a, b, answer; +vector line; +stack> st; + +// a1 b ũ +// a1 b ۴ٸ b +void Solve() +{ + cin >> N; + + for (int i = 0; i < N; i++) + { + cin >> n; + line.push_back(n); + } + + for (auto num : line) + { + int cnt = 1; + + while (!st.empty()) + { + int cur = st.top().first; + int cur_cnt = st.top().second; + if (cur < num) + { + answer+= cur_cnt; + } + else if (cur == num) + { + answer += cur_cnt; + cnt += cur_cnt; + } + else //if(st.top().first > num) + { + answer++; + break; + } + st.pop(); + } + //cout << num << ", " << answer << "\n"; + st.push({num, cnt}); + } + + cout << answer; +} + +int main() +{ + cin.tie(nullptr); + ios::sync_with_stdio(false); + + Solve(); + + return 0; +} \ No newline at end of file From dbb1edb41aa504214a44ea55927db7dcc37d6b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=A0=EC=9A=B0?= <51250442+InSange@users.noreply.github.com> Date: Thu, 2 May 2024 01:56:08 +0900 Subject: [PATCH 2/2] 10-InSange --- InSange/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InSange/README.md b/InSange/README.md index 1542bc2..b4aad18 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -11,6 +11,6 @@ | 7차시 | 2024.04.04 | 스택 | [문자열 폭발](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] | 8차시 | 2024.04.09 | 투 포인터 | [두 용액](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/32)] | 9차시 | 2024.04.12 | 힙 | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] -| 10차시 | 2024.05.02 | 스택 | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)] +| 10차시 | 2024.05.02 | 스택 | [오아시스 재결합](https://www.acmicpc.net/problem/3015) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/40)] ======= ---