Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10-InSange #40

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
---
62 changes: 62 additions & 0 deletions InSange/스택/3015.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

long long N, n, a, b, answer;
vector<int> line;
stack<pair<int, int>> 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;
}