Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π λ¬Έμ λ§ν¬
κ΅¬κ° λλκΈ° 2
βοΈ μμλ μκ°
1μκ° νΈλΌμ΄νκ³ λ νΌλ°μ€ νμΈ
β¨ μλ μ½λ
1. λ¬Έμ
Nκ°μ μλ‘ μ΄λ£¨μ΄μ§ 1μ°¨μ λ°°μ΄μ΄ μλ€. μ΄ λ°°μ΄μ Mκ° μ΄νμ ꡬκ°μΌλ‘ λλμ΄μ ꡬκ°μ μ μμ μ΅λκ°μ μ΅μλ‘ νλ €κ³ νλ€. ꡬκ°μ λ€μκ³Ό κ°μ 쑰건μ λ§μ‘±ν΄μΌ νλ€.
ꡬκ°μ μ μλ ꡬκ°μ μν μμ μ΅λκ°κ³Ό μ΅μκ°μ μ°¨μ΄μ΄λ€.
μλ₯Ό λ€μ΄, λ°°μ΄μ΄ [1, 5, 4, 6, 2, 1, 3, 7] μ΄κ³ , M = 3μΈ κ²½μ°κ° μλ€.
μ΄λ, [1, 5], [4, 6, 2], [1, 3, 7]λ‘ κ΅¬κ°μ λλλ©΄ κ° κ΅¬κ°μ μ μλ 4, 4, 6μ μ΄ λλ€. μ΄λ, μ΅λκ°μ 6μ μ΄λ€.
λ§μ½, [1, 5, 4], [6, 2, 1], [3, 7]λ‘ κ΅¬κ°μ λλμλ€λ©΄, κ° κ΅¬κ°μ μ μλ 4, 5, 4μ μ΄ λκ³ , μ΄λ μ΅λκ°μ 5μ μ΄ λλ€.
λ κ²½μ° μ€μμ μ΅λκ°μ΄ μ΅μμΈ κ²μ 5μ μΈ κ²μ΄κ³ , 5μ λ³΄λ€ μ΅λκ°μ μκ² λ§λλ λ°©λ²μ μλ€.
λ°°μ΄κ³Ό Mμ΄ μ£Όμ΄μ‘μ λ, ꡬκ°μ μ μμ μ΅λκ°μ μ΅μκ°μ ꡬνλ νλ‘κ·Έλ¨μ μμ±νμμ€.
2. νμ΄
Mκ° μ΄νμ ꡬκ°μΌλ‘ λ°°μ΄μ λλ μΌ νλλ°, μ΄λ₯Ό 무μνκ² λ€ λ€λ£¨κΈ°μ κ²½μ°μ μκ° λ무 λ§λ€. λ¨μν Mμ΄ μ΅λ NκΉμ§ κ°κΈ°λ νκ³ , μ¬μ§μ΄ M "μ΄ν"μ΄κΈ° λλ¬Έμ κ²½μ°μ μλ νλ°μ μΌλ‘ λμ΄λλ€.
λ¬Έμ μμ ꡬνκ³ μ νλ 건 κ΅¬κ° μ μ μ΅λκ° μ€ μ΅μκ°μΈλ°, μ¬κΈ°μ κ΅¬κ° μ μ(ν΄λΉ ꡬκ°μ μ΅λκ° - μ΅μκ°)μ μ£Όλͺ©νλ€.
μ΄ μ μ μ°¨μ΄λ₯Ό νμμ keyλ‘ νμ¬, "μ 체 λ°°μ΄μ Mκ° μ΄νλ‘ λΆν ν μ μλ" κ²λ€ μ€ κ°μ₯ μμ μ μλ₯Ό ꡬν΄λ΄λ©΄ μ λ΅μ΄λ€. μ΄ λ "μ΄μ§ νμ"μΌλ‘ μννλ€. κ·Έλ¬λ©΄ μκ° λ³΅μ‘λλ$Nlog(N)$ μΌλ‘ μΆ©λΆν ν΄κ²° κ°λ₯νλ€.
ꡬκ°μ μ μ μ°¨μ΄λ μ΅μ 0μ (κ΅¬κ° λ΄ λͺ¨λ μ«μκ° λμΌν¨)λΆν° μ΅λ 9999μ (λ°°μ΄μ μλ μ΅μ 1, μ΅λ 10000)μ΄λ€. μ΄ λ²μ λ΄μμ νκ² μ μλ₯Ό μ°Ύμλ³Έλ€. μ΄κΈ°κ°μ Maxμ΄λ€.
μ νμ μΈ μ΄μ§νμ λ‘μ§μ΄λ€. IsValid() ν¨μμ κ²°κ³Όκ° trueμ΄λ©΄ 쑰건μ λΆν©ν μΆμ μ μλΌ μ΄λ₯Ό minimum update μννλ€.
ν΅μ¬ λ‘μ§μ΄λ€. μλ₯Ό λ€μ΄λ³΄μ: [1, 5, 4, 6, 2, 1, 3, 7], M = 3
λ°λΌμ μ λ΅μ 5μ΄λ€.
μ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
μ΄ λ¬Έμ λ 2024 NHN κ²μ κ³΅μ± μ½λ© ν μ€νΈ λ¬Έμ μ μ μ¬νλ€(λμ€μ½λμ κ΄λ ¨ ν¬μ€νΈκ° μμΌλ λ§κ΄λΆ!).
μ½ν μΉ λΉμμλ μ΄λ€ μ νμΈμ§ νμ νμ§ λͺ»ν΄ λͺ» νμλλ° @mjj111 λμ΄ "μ΄κ±° μ΄μ§νμμ!" ν΄μ λμ λΆμ ν€κ³ λ°±μ€ λ€μ Έλ³΄λ λΉμ·ν κ² μ΄ λ¬Έμ μλ€.
νΈλΌμ΄ ν΄λ΄€μ§λ§... 1μκ° λμ κ°λ λͺ»μ‘κ³ λ νΌλ°μ€ νμΈνκ³ λμμΌ κ²¨μ°κ²¨μ° λμ μΌ μ μμλ...
νλμ λ°±νΈλνΉ/μ΄μ§νμ/그리λ/DP μμ£Όλ‘ νμ΄μΌκ² λ€.
p.s. μ°Έκ³ λ‘ μ΄ λ¬Έμ λ Nμ ν¬κΈ°κ° μμ΄μ λ€μκ³Ό κ°μ΄ μ ν νμμ ν΄λ ν΅κ³Όνλ€.
(μκ° μ ννμ, μλκ° μ΄μ§νμ)