프로그래밍/문제풀이
백준 3015 오아시스 재결합
하용권
2018. 11. 10. 23:37
https://www.acmicpc.net/problem/3015
키가 같은 경우에서 애 먹었습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> #include <stack> using namespace std; int main(){ ios_base::sync_with_stdio(false); //cin 속도 증가시키기 위해 stack<pair<int,int>> st; //first는 키, second는 키가 같은 경우 int N,tmp, chk; //tmp는 키, chk는 키가 같은 경우 long long count = 0; cin >> N; for(int i = 0; i < N; i++){ cin >> tmp; chk = 1; while(!st.empty() && st.top().first <= tmp){ count += st.top().second; if(st.top().first == tmp) chk+= st.top().second; st.pop(); } if(!st.empty()) count +=1;; st.push({tmp,chk}); } cout << count; } | cs |
반응형