Skip to content

Commit fadbbbd

Browse files
committed
[TimeComplexity] baekjoon-14003
1 parent 6d95c72 commit fadbbbd

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

โ€ŽREADME.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
| 08 | | [Codility-Lesson3 TapeEquilibrium](./src/TimeComplexity/TapeEquilibrium) | |
310310
| 09 | | [Baekjoon-12015 ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 2](./src/TimeComplexity/P12015) | LIS |
311311
| 10 | | [Baekjoon-12738 ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 3](./src/TimeComplexity/P12738) | LIS |
312+
| 11 | | [Baekjoon-14003 ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 5](./src/TimeComplexity/P14003) | LIS |
312313

313314
## Series
314315

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package TimeComplexity.P14003;
2+
3+
import java.io.*;
4+
import java.util.StringTokenizer;
5+
6+
public class Main {
7+
8+
static int N, last = 0;
9+
static int[] A, L, P;
10+
11+
public static void main(String[] args) throws Exception {
12+
System.setIn(new FileInputStream("src/TimeComplexity/P14003/input.txt"));
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
StringBuilder sb = new StringBuilder();
15+
16+
N = Integer.parseInt(br.readLine());
17+
A = new int[N];
18+
L = new int[N];
19+
P = new int[N];
20+
21+
StringTokenizer st = new StringTokenizer(br.readLine());
22+
for (int i = 0; i < N; i++) A[i] = Integer.parseInt(st.nextToken());
23+
24+
L[0] = A[0];
25+
P[0] = 0;
26+
for (int i = 0; i < N; i++) {
27+
if (L[last] < A[i]) {
28+
L[++last] = A[i];
29+
P[i] = last;
30+
} else {
31+
int low = 0, high = last, k = A[i];
32+
while (low < high) {
33+
int mid = (low+high)/2;
34+
if (L[mid] < k) low = mid+1;
35+
else high = mid;
36+
}
37+
L[low] = k;
38+
P[i] = low;
39+
}
40+
}
41+
42+
int cnt = last;
43+
for (int i = N-1; i >= 0; i--) {
44+
if (P[i] == cnt) {
45+
sb.insert(0, A[i] + " ");
46+
cnt--;
47+
}
48+
if (cnt == -1) break;
49+
}
50+
51+
System.out.println(last+1);
52+
System.out.println(sb.toString());
53+
}
54+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [baekjoon-14003] ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 5
2+
3+
![image](https://user-images.githubusercontent.com/22045163/107529400-2ca7ed00-6bfe-11eb-8310-9dd6a7fd19ea.png)
4+
5+
![image](https://user-images.githubusercontent.com/22045163/107529432-35002800-6bfe-11eb-9000-17eb2782782b.png)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
6
2+
10 20 10 30 20 50
3+
4+
8
5+
3 2 5 2 3 1 4 1
6+

0 commit comments

Comments
ย (0)