Skip to content

Commit

Permalink
가장 긴 증가하는 부분수열2
Browse files Browse the repository at this point in the history
  • Loading branch information
jungwoo1208 authored May 27, 2024
1 parent 4f8183f commit 40a9568
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 강정우/Boj12015.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>
using namespace std;
vector<int> a, res;
int binary(int k) {
int start = 0;
int end = res.size() - 1;
int mid;
while (start < end) {
mid = start + (end - start) / 2;
if (res[mid] >= k)
end = mid;
else
start = mid + 1;
}
return end;
}
int main() {
int n, t, idx;
cin >> n;
for (int i = 0; i < n; i++){
cin >> t;
a.push_back(t);
}
res.push_back(a.front());

for (int i = 1; i < n; i++) {
if (a[i] > res.back())
res.push_back(a[i]);
else {
idx = binary(a[i]);
res[idx] = a[i];
}
}
cout << res.size();
return 0;
}

0 comments on commit 40a9568

Please sign in to comment.