https://www.acmicpc.net/problem/12789
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void CPP_INIT() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(void) {
CPP_INIT();
int input;
int num;
int s = 1;
stack<int> st;
cin >> input;
for (int i = 0; i < input; i++) {
while (!st.empty() && s == st.top()) {
s++;
st.pop();
}
cin >> num;
if (s != num) {
if (!st.empty() && st.top() == num) {
st.pop();
s++;
}
else st.push(num);
}
else {
s++;
}
}
while (!st.empty()) {
if (s == st.top()) {
st.pop();
s++;
}
else break;
}
if (st.empty()) cout << "Nice";
else cout << "Sad";
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 28279 덱 2 (0) | 2025.01.12 |
---|---|
C++ 알고리즘 - 백준 18528 큐 2 (0) | 2025.01.12 |
C++ 알고리즘 - 백준 28728 스택 2 (0) | 2025.01.12 |
C++ 알고리즘 - 백준 17103 골드바흐 파티션 (에라토스테네스의 체) (0) | 2025.01.12 |
C++ 알고리즘 - 백준 4948 베르트랑 공준 (에라토스테네스의 체) (0) | 2025.01.12 |