baekjoon 20260207
This commit is contained in:
parent
42a6d794e5
commit
2b24a0a06c
1
code_study/Baekjoon/python/13866.py
Normal file
1
code_study/Baekjoon/python/13866.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print((lambda x: abs((x[3] + x[0]) - (x[1] + x[2])))(list(map(int, input().split()))))
|
||||||
36
code_study/Baekjoon/swift/1509.swift
Normal file
36
code_study/Baekjoon/swift/1509.swift
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
func solve() -> Int {
|
||||||
|
guard let input = readLine() else { return -1 }
|
||||||
|
let str = Array(input)
|
||||||
|
let N = str.count
|
||||||
|
|
||||||
|
var isPalindrom: [[Bool]] = Array(repeating: Array(repeating: false, count: N), count: N)
|
||||||
|
|
||||||
|
for len in 1...N {
|
||||||
|
for start in 0...N-len {
|
||||||
|
let end = start + len - 1
|
||||||
|
|
||||||
|
if (len == 1) || (len == 2 && str[start] == str[end]) || (str[start] == str[end] && isPalindrom[start+1][end-1]) {
|
||||||
|
isPalindrom[start][end] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dp: [Int] = Array(repeating: 2501, count: N)
|
||||||
|
|
||||||
|
for end in 0..<N {
|
||||||
|
for start in 0...end {
|
||||||
|
if isPalindrom[start][end] {
|
||||||
|
if start == 0 {
|
||||||
|
dp[end] = 1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dp[end] = min(dp[start - 1] + 1, dp[end])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dp[N-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
print(solve())
|
||||||
Loading…
x
Reference in New Issue
Block a user