Skip to content

Commit 87078de

Browse files
committed
[TimeComplexity] baekjoon-12015
1 parent 2e98b84 commit 87078de

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

โ€ŽREADME.md

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
| 06 | | [Codility-Lesson3 FrogJmp](./src/TimeComplexity/FrogJmp) | |
307307
| 07 | | [Codility-Lesson3 PermMissingElem](./src/TimeComplexity/PermMissingElem) | |
308308
| 08 | | [Codility-Lesson3 TapeEquilibrium](./src/TimeComplexity/TapeEquilibrium) | |
309+
| 09 | | [Baekjoon-12015 ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 2](./src/TimeComplexity/P12015) | LIS |
309310

310311
## Series
311312

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package TimeComplexity.P12015;
2+
3+
import java.io.*;
4+
import java.util.StringTokenizer;
5+
6+
public class Main {
7+
8+
static int N, L_idx;
9+
static int[] A, L;
10+
11+
public static void main(String[] args) throws Exception {
12+
System.setIn(new FileInputStream("src/TimeComplexity/P12015/input.txt"));
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
15+
N = Integer.parseInt(br.readLine());
16+
A = new int[N];
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
for (int i = 0; i < N; i++) A[i] = Integer.parseInt(st.nextToken());
19+
20+
L = new int[N];
21+
L[0] = A[0];
22+
for (int i = 1; i < N; i++) {
23+
if (L[L_idx] < A[i]) L[++L_idx] = A[i];
24+
else L[getLowerBound(A[i])] = A[i];
25+
}
26+
27+
System.out.println(L_idx + 1);
28+
}
29+
30+
static int getLowerBound(int k) {
31+
int low = 0, high = L_idx;
32+
while (low < high) {
33+
int mid = (low + high) / 2;
34+
if (L[mid] < k) {
35+
low = mid + 1;
36+
} else {
37+
high = mid;
38+
}
39+
}
40+
return low;
41+
}
42+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [baekjoon-12015] ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 2
2+
3+
![image](https://user-images.githubusercontent.com/22045163/107511185-7f76aa00-6be8-11eb-899e-c537dad90a69.png)
4+
5+
![image](https://user-images.githubusercontent.com/22045163/107511204-869db800-6be8-11eb-8d16-7fba4ec44ff5.png)
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
6
2+
10 20 10 30 20 50
3+
4+
6
5+
10 5 10 20 30 50
6+
7+
10
8+
1 100 2 50 60 3 5 6 7 8

0 commit comments

Comments
ย (0)