Skip to content

Commit

Permalink
20-yuyu0830
Browse files Browse the repository at this point in the history
20-yuyu0830
  • Loading branch information
yuyu0830 authored Aug 5, 2024
2 parents d36d10d + 299cddd commit bb05371
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
76 changes: 76 additions & 0 deletions yuyu0830/LIS/14003.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
#include <map>
#include <vector>

#define NUM 1000010
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using namespace std;

typedef pair<int, int> ii;

int cnt = 0;
int arr[NUM] = {0, };
vector<ii> 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<int> 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();
}
}
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
| 17μ°¨μ‹œ | 2024.07.02 | μœ„μƒμ •λ ¬ | [ACM Craft](https://www.acmicpc.net/problem/1005) | - |
| 18μ°¨μ‹œ | 2024.07.06 | κ΅¬ν˜„ | [2048 (Easy)](https://www.acmicpc.net/problem/12100) | - |
| 19μ°¨μ‹œ | 2024.07.12 | μž¬κ·€ | [μš°μˆ˜λ§ˆμ„](https://www.acmicpc.net/problem/1949) | - |
| 20μ°¨μ‹œ | 2024.07.22 | LIS | [κ°€μž₯ κΈ΄ μ¦κ°€ν•˜λŠ” λΆ€λΆ„ μˆ˜μ—΄ 5](https://www.acmicpc.net/problem/14003) | - |
---

0 comments on commit bb05371

Please sign in to comment.