Skip to content

Commit 42f6dae

Browse files
authored
Merge pull request #369 from AlgorithmWithGod/lkhyun
[20250618] BOJ / G2 / 가장 긴 증가하는 부분 수열 / 이강현
2 parents 5cc5a39 + 56d6672 commit 42f6dae

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int N;
10+
static List<Integer> LIS;
11+
12+
public static void main(String[] args) throws IOException {
13+
N = Integer.parseInt(br.readLine());
14+
LIS = new ArrayList<>();
15+
st = new StringTokenizer(br.readLine());
16+
for (int i = 0; i < N; i++) {
17+
int cur = Integer.parseInt(st.nextToken());
18+
if(LIS.isEmpty() || LIS.get(LIS.size()-1) < cur){
19+
LIS.add(cur);
20+
}else{
21+
LIS.set(binarySearch(cur),cur);
22+
}
23+
}
24+
bw.write(LIS.size() + "\n");
25+
bw.close();
26+
}
27+
public static int binarySearch(int target) {
28+
int left = 0; int right = LIS.size() - 1;
29+
while(left < right){
30+
int mid = (left + right) / 2;
31+
if(LIS.get(mid) < target){
32+
left = mid + 1;
33+
}else{
34+
right = mid;
35+
}
36+
}
37+
return left;
38+
}
39+
}
40+
```

0 commit comments

Comments
 (0)