Skip to content

Commit

Permalink
10-InSange
Browse files Browse the repository at this point in the history
10-InSange
  • Loading branch information
InSange authored May 20, 2024
2 parents 3ded618 + ce4e89f commit 11b5d76
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
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;
}

0 comments on commit 11b5d76

Please sign in to comment.