6198번: 옥상 정원 꾸미기 (acmicpc.net)
6198번: 옥상 정원 꾸미기
문제 도시에는 N개의 빌딩이 있다. 빌딩 관리인들은 매우 성실 하기 때문에, 다른 빌딩의 옥상 정원을 벤치마킹 하고 싶어한다. i번째 빌딩의 키가 hi이고, 모든 빌딩은 일렬로 서 있고 오른쪽으
www.acmicpc.net
배운것
코드 보면서 흐름이해
정답풀이
// Authored by : unluckyjung
// Co-authored by : BaaaaaaaaaaarkingDog
// http://boj.kr/a84f083cdee3436f9f46acdef175e55f
#include <bits/stdc++.h>
using namespace std;
#define ll long long
stack<int> s;
int n;
ll ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
ll h;
while (n--) {
cin >> h;
while(!s.empty() && s.top() <= h)
s.pop();
ans += s.size();
s.push(h);
}
cout << ans;
return 0;
}
'Algorithm > C++' 카테고리의 다른 글
[백준 2583] 영역 구하기 (0) | 2022.09.04 |
---|---|
[백준 17298] 오큰수 (0) | 2022.09.03 |
[백준 7562] 나이트의 이동 (0) | 2022.09.01 |
[백준 5427] 불 (0) | 2022.08.31 |
[백준 1874] 스택 수열 (0) | 2022.08.31 |
댓글