From 3c50858597998c827073f07ed416cf29c3c18555 Mon Sep 17 00:00:00 2001 From: yuyu0830 Date: Mon, 22 Jul 2024 22:22:47 +0900 Subject: [PATCH] =?UTF-8?q?24-07-22=20=EA=B0=80=EC=9E=A5=20=EA=B8=B4=20?= =?UTF-8?q?=EC=A6=9D=EA=B0=80=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=97=B4=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuyu0830/LIS/14003.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ yuyu0830/README.md | 3 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 yuyu0830/LIS/14003.cpp diff --git a/yuyu0830/LIS/14003.cpp b/yuyu0830/LIS/14003.cpp new file mode 100644 index 0000000..f2ed9e5 --- /dev/null +++ b/yuyu0830/LIS/14003.cpp @@ -0,0 +1,76 @@ +#include +#include +#include + +#define NUM 1000010 +#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); + +using namespace std; + +typedef pair ii; + +int cnt = 0; +int arr[NUM] = {0, }; +vector v[NUM]; + +// 이진 탐색 +int bs(int value) { + int low = 0, mid, high = cnt; + + while (low <= high) { + mid = (low + high) / 2; + + if (v[mid].back().first == value) + return -1; + + if (value < v[mid].back().first) high = mid - 1; + else low = mid + 1; + } + + return mid + (value < v[mid].back().first ? -1 : 0); +} + +int main() { + fastio; + + int n; cin >> n; + + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + + // 오류 대비 초기값 + v[0].push_back(make_pair(-1000000001, 0)); + + for (int i = 0; i < n; i++) { + int l = arr[i]; + + if (l > v[cnt].back().first) { + // 만약 가장 큰 값이면 맨 앞에 두기 + v[++cnt].push_back(make_pair(l, v[cnt - 1].size())); + continue; + } + + // 중간에 들어가야하는 값이면 앞의 요소가 뭔지 저장한 뒤에 벡터에 보관 + int t = bs(l) + 1; + if (t == 0) continue; + + v[t].push_back(make_pair(l < v[t].back().first ? l : v[t].back().first, v[t - 1].size())); + } + + printf("%d\n", cnt); + + // 가장 끝 요소부터 역순으로 순서 찾아오기 + vector ans; + ii tmp = v[cnt--][0]; + + do { + ans.push_back(tmp.first); + tmp = v[cnt][tmp.second - 1]; + } while(cnt--); + + while (!ans.empty()) { + printf("%d ", ans.back()); + ans.pop_back(); + } +} \ No newline at end of file diff --git a/yuyu0830/README.md b/yuyu0830/README.md index 465df48..094c9ce 100644 --- a/yuyu0830/README.md +++ b/yuyu0830/README.md @@ -16,5 +16,6 @@ | 12차시| 2024.05.13 | 해시 | [두 배열의 합](https://www.acmicpc.net/problem/2143) | - | | 13차시| 2024.05.21 | LIS | [가장 긴 증가하는 부분 수열 2](https://www.acmicpc.net/problem/12015) | - | | 15차시| 2024.06.01 | 기하 | [다각형의 면적](https://www.acmicpc.net/problem/2166) | - | -| 16차시 | 2024.06.04 | 별자리 만들기 | [별자리 만들기](https://www.acmicpc.net/problem/4386) | - | +| 16차시 | 2024.06.04 | MST | [별자리 만들기](https://www.acmicpc.net/problem/4386) | - | +| 20차시 | 2024.07.22 | LIS | [가장 긴 증가하는 부분 수열 5](https://www.acmicpc.net/problem/4386) | - | --- \ No newline at end of file