-
[12789] 도키도키 간식드리미BOJ 2022. 4. 12. 11:04
https://www.acmicpc.net/problem/12789
12789번: 도키도키 간식드리미
인하대학교 학생회에서는 중간, 기말고사 때마다 시험 공부에 지친 학우들을 위해 간식을 나눠주는 간식 드리미 행사를 실시한다. 승환이는 시험 기간이 될 때마다 간식을 받을 생각에 두근두
www.acmicpc.net
tar = 1로 놓고, 현재 값==tar이면 tar를 증가시키고, stack.top()!=tar일때까지 간식을 먼저 받는다.
현재 값이 tar가 아닐때에는 전부 스택에 넣고, 마지막에 한번 더 stack.top()!=tar인 경우를 체크해서 "Sad"를 판
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;stack<int> st;int n, tar = 1;int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> n;int i;for (i = 0; i < n; i++) {int x;cin >> x;if (x == tar) {tar++;while (!st.empty()) {int t = st.top();if (t != tar) break;tar++;st.pop();}continue;}st.push(x);}while (!st.empty()) {int t = st.top();st.pop();if (t != tar) {cout << "Sad";return 0;}tar++;}cout << "Nice";return 0;}
'BOJ' 카테고리의 다른 글
[14500] 테트로미노 (0) 2022.04.22 [3584] 가장 가까운 공통 조상 (0) 2022.04.15 [3787] Count on Canton (0) 2022.04.09 [5525] IOIOI (0) 2022.04.07 [9375] 패션왕 신해빈 (0) 2022.04.07