·960 words·5 mins
π λ¬Έμ μ 보 # λ§ν¬: https://www.acmicpc.net/problem/34609 λ²μ λ¬Έμ # $1$λ²λΆν° $n$λ²κΉμ§ λ²νΈκ° λ§€κ²¨μ§ $n$μ‘μ΄μ κ½μ΄ μΌμͺ½μμ μ€λ₯Έμͺ½μΌλ‘ μΌλ ¬λ‘ λμ¬ μλ€. κ° κ½μ λ°±ν©(lily) λλ μ₯λ―Έ(rose) μ€ νλμ΄λ€. $0$ μ΄μ $n$ μ΄νμ μ μ $j$μ λν΄, $l_j$λ₯Ό μΌμͺ½ $j$κ°μ κ½ μ€ λ°±ν©μ μ, $r_j$λ₯Ό μ€λ₯Έμͺ½ $n - j$κ°μ κ½ μ€ μ₯λ―Έμ μλΌ νμ.
·292 words·2 mins
π λ¬Έμ μ 보 # λ§ν¬: https://www.acmicpc.net/problem/31498 π§ κ΄μ°° λ° μ κ·Ό # μ§ - ν μΉ΄ - λλμ΄ ννλ‘ μλ κ² κ°λ€. λ§€ μνλ§λ€ ν μΉ΄λ $B, B-K, B-2*K \cdots$ λ§νΌ μμ§μ΄κ³ , λλμ΄λ $D$λ§νΌ κ³μ μμ§μΈλ€. ν μΉ΄κ° μ‘νλ€λ©΄, κ·Έ μκ° ν μΉ΄κ° μμ§μΈ κΈΈμ΄λ $D$λ³΄λ€ μμ κ²μ΄λ€. λ°λΌμ ν μΉ΄κ° μ΄λ μκ° μ‘νλ€λ©΄, ν μΉ΄μ λλμ΄κ° κ³μ μμ§μΈλ€κ³ κ°μ νλ©΄ λλμ΄λ ν μΉ΄λ³΄λ€ ν¨μ¬ μΌμͺ½μ μκ² λλ€. λ°λΌμ μκ°μ ν μΉ΄μ λλμ΄μ μμΉμ λ¨μ‘°μ±μ΄ μ‘΄μ¬νλ€. μ΄λΆ νμμ μ΄μ©ν μ μκ² λ€. ν μΉ΄κ° μ§μ λμ°©νμ§λ λͺ»νλ μν©, $K$κ° 0μΈμν© λ± μ¬λ¬κ°μ§ μμΈ μν©μ μ‘°μ¬νμ. π» νμ΄ # μ½λ (python): A, B = map(int, input().split()) C, D = map(int, input().split()) K = int(input()) # ν μΉ΄κ° μ§μ λμ°©ν μλ μλκ°? # B + (B-K) + (B-2K) + ... >= A if K > 0: # K = 0μ΄λ©΄ 무쑰건 λμ°©ν μ μμ cnt = B // K # B - cnt * K >= 0 μΈ μ΅λ cnt tot = B * (cnt + 1) - K * (cnt * (cnt + 1)) // 2 # B + (B-K) + ... + (B - cnt * K) if tot < A: print(-1) exit(0) # ν μΉ΄κ° μ§μ λμ°©νλ νμ΄λ°μ΄ λλμ΄λ³΄λ€ μ΄λ₯Έκ°? def toka_move(time): if K > 0: time = min(time, B // K + 1) return B * time - K * (time * (time - 1)) // 2 ok, ng = 10**12, 0 # ν μΉ΄κ° μ§μ λμ°©νλ κ°μ₯ λΉ λ₯Έ νμ΄λ° while ok - ng > 1: mid = (ok + ng) // 2 if toka_move(mid) >= A: ok = mid else: ng = mid if D*ok < A + C: # μμ§ λλμ΄κ° λμ°©νμ§ μμλ€λ©΄ print(ok) else: print(-1) π ꡬν μ½λ μ κΈ
·238 words·2 mins
π λ¬Έμ μ 보 # λ§ν¬: https://www.acmicpc.net/problem/20929 π§ κ΄μ°° λ° μ κ·Ό # λ¬Έμ μ μ νμΈ $2^{19}$μ νμλ₯Ό λ³Όλ, μ΄λΆ νμμ μ₯λ €νκ³ μλ κ² κ°λ€. λ€μκ³Ό κ°μ μν©μ μκ°ν΄λ³΄μ. ![[Drawing 2026-02-10 14.25.24.excalidraw.png]] κΈΈμ΄ 8μ λ°°μ΄ 2κ°μμ λ€μκ³Ό κ°μ΄ $N/2$λ²μ§Έ μμΈ 4λ²μ§Έ μλ₯Ό λΉκ΅νμ λ, μμ κ°μ΄ μμ λ°°μ΄μ μλ μ λ°κ³Ό ν° λ°°μ΄μ μμͺ½ μ λ°μ κ³ λ €ν νμκ° μμ΄μ§λ€. ![[Drawing 2026-02-10 14.31.00.excalidraw.png]] μμ λ§μ°¬κ°μ§λ‘, μμμ μμ λ°°μ΄ μͺ½ 4κ°λ₯Ό μ μΈνκ³ λ³΄λ©΄ $N$μ΄ μ λ°μΌλ‘ μ€μ΄λ μν©μμ κ°μ λ°©μμΌλ‘ λ°λ³΅ν μ μμμ μ μ μλ€. λ°λΌμ μμ κ°μ κ³Όμ μ 1κ°κ° λ¨μλκΉμ§ λ°λ³΅νλ©΄ λ κ°μ κ°κ° $N, N+1$λ²μ§Έ κ°μΌ κ²μ΄λ€. λ¬Έμ μμλ $N$λ²μ§Έ μλ₯Ό μꡬνμΌλ―λ‘, λ μμ μλ₯Ό μΆλ ₯νμ. π» νμ΄ # μ½λ (python): def Query(s, idx): """ μ§λ¬Έ "? s idx"μ νκ³ μ
λ ₯λ°λ ν¨μ """ print("?", s, idx) return int(input()) N = int(input()) A_Lidx = 1 A_Ridx = N # [A_Lidx ~ A_Ridx] μ μ λ΅ νλ³΄κ° μμ B_Lidx = 1 B_Ridx = N # [B_Lidx ~ B_Ridx] μ μ λ΅ νλ³΄κ° μμ while A_Ridx > A_Lidx: A_mid = (A_Lidx + A_Ridx) // 2 B_mid = (B_Lidx + B_Ridx) // 2 A_ret = Query("A", A_mid) B_ret = Query("B", B_mid) if A_ret <= B_ret: A_Lidx = A_mid + 1 B_Ridx = B_mid else: A_Ridx = A_mid B_Lidx = B_mid + 1 A_ret = Query("A", A_Lidx) B_ret = Query("B", B_Lidx) print("!", min(A_ret, B_ret)) π ꡬν μ½λ μ κΈ