Created
October 3, 2019 07:58
-
-
Save victoriagjh/b545c582a17231b5bd0243935ce09892 to your computer and use it in GitHub Desktop.
생각을 더 꼼꼼히!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <stack> | |
using namespace std; | |
int n; | |
int map[1000002]; | |
int p1[1000002]; | |
int t[1000002]; | |
stack<int> st; | |
int main() { | |
cin>>n; | |
for(int i=1; i<=n; i++) | |
scanf("%d",&map[i]); | |
t[1]=map[1]; | |
p1[1]=1; | |
int pIndex=1; | |
for(int i=2; i<=n; i++) { | |
if(map[i]>t[pIndex]) { | |
pIndex++; | |
p1[i]=pIndex; | |
t[pIndex]=map[i]; | |
} else { | |
int lowIndex = lower_bound(t+1, t+pIndex, map[i])-t; | |
p1[i]=lowIndex; | |
t[lowIndex]=map[i]; | |
} | |
} | |
int len = pIndex; | |
for(int i=n; i>=1; i--){ | |
if(p1[i]==len) { | |
st.push(map[i]); | |
len--; | |
} | |
} | |
cout<<pIndex<<endl; | |
while (!st.empty()) { | |
printf("%d ",st.top()); | |
st.pop(); | |
} | |
cout<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment