baekjoon 20260110
This commit is contained in:
parent
95e79a15e9
commit
38b311b802
43
code_study/Baekjoon/swift/12015.swift
Normal file
43
code_study/Baekjoon/swift/12015.swift
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
func solve() -> Int {
|
||||||
|
guard let N = Int(readLine() ?? ""),
|
||||||
|
let input = readLine()
|
||||||
|
else { return 0 }
|
||||||
|
|
||||||
|
let A: [Int] = input.split(separator: " ").compactMap{Int($0)}
|
||||||
|
if A.count != N { return -1 }
|
||||||
|
|
||||||
|
var LIS: [Int] = []
|
||||||
|
|
||||||
|
for now in A {
|
||||||
|
if LIS.isEmpty {
|
||||||
|
LIS.append(A[0])
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let lastNum: Int = LIS.last else { break }
|
||||||
|
|
||||||
|
if lastNum < now {
|
||||||
|
LIS.append(now)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var l = 0, r = LIS.count-1
|
||||||
|
|
||||||
|
while l < r {
|
||||||
|
let mid: Int = (l+r)/2
|
||||||
|
|
||||||
|
if LIS[mid] < now {
|
||||||
|
l = mid + 1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
r = mid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LIS[l] = now
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return LIS.count
|
||||||
|
}
|
||||||
|
|
||||||
|
print(solve())
|
||||||
Loading…
x
Reference in New Issue
Block a user