728x90
이 문제는 특정한 사정으로 다시 한번 공부하게 되었는데 다른 사람들의 코드를 조금더 쉽게 풀어서 작업하였다.
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main() {
Fast;
int n;
cin >> n;
vector<int> arr;
for (int i = 0; i < n; i++) {
int in;
cin >> in;
if (arr.size() == 0) {
arr.push_back(in);
}
else {
int index = lower_bound(arr.begin(), arr.end(), in) - arr.begin();
if (index == arr.size()) {
arr.push_back(in);
}
else {
arr[index] = in;
}
}
}
cout << arr.size() << endl;
return 0;
}
후기
시험만 보면 왜이렇게 머리가 안돌아갈까..
728x90
'알고리즘문제 풀어보기 > 백준' 카테고리의 다른 글
백준 - 9202 Boqqle <트라이 연습하기> (0) | 2024.11.04 |
---|---|
백준 - 3025 돌던지기 (게임에서 falling sand 같은 느낌) (0) | 2024.10.31 |
백준 - 2665 미로 만들기 (0) | 2024.10.24 |
백준-2515 전시장 (0) | 2024.10.24 |
백준 - 11444 피보나치 수열 6 (0) | 2024.10.24 |