하다보니

2493번-탑 본문

알고리즘 풀이/백준

2493번-탑

claire 2022. 1. 22. 22:57
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	stack<pair<int, int>> tower;
	cin >> n;
	tower.push({ 100000001,0 });
	for (int i = 1; i <= n; i++) {
		int height;
		cin >> height;
		while (tower.top().X < height)
			tower.pop();
		cout << tower.top().Y << ' ';
		tower.push({ height,i });
	}
}

pair를 알게된 좋은 문제ㅎㅎ

'알고리즘 풀이 > 백준' 카테고리의 다른 글

2164번-카드2  (0) 2022.01.23
10845번-큐  (0) 2022.01.23
1874번-스택 수열  (0) 2022.01.22
10773번-제로  (0) 2022.01.22
5397번-키로거  (0) 2022.01.18