diff --git a/InSange/README.md b/InSange/README.md index 441d9b2..358e16c 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -10,5 +10,6 @@ | 6차시 | 2024.04.01 | 최소신장트리 | [행성 터널](https://www.acmicpc.net/problem/2887) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/24)] | 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/problems/top-k-frequent-words/) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/34)] +| 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 | 스택 | [오아시스 재결합](https://www.acmicpc.net/problem/3015) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/40)] --- 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