E. Hoofball
-iknoom1107
λ¬Έμ μ€λͺ
κ° μλ κ°κΉμ΄ μνν λ§ κ³΅μ ν¨μ€ν μ μμ΅λλ€.
Nμ΄ μ΅λ 100μ΄λΌ N^2μΌλ‘ νμ΄λ μΆ©λΆν©λλ€.
Nκ°μ μ μ€μμ νλ²μ κ°μ₯ λ§μ μμκ² ν¨μ€ν μ μλ μλ₯Ό νμν©λλ€.
곡μ ν¨μ€λ°μ§ μμ μμ λν΄μλ§ 1λ²μ λ°λ³΅ν©λλ€.
Nλ§λ¦¬μ μμ λν΄μ κ°μ₯ κ°κΉμ΄ μμ λ²νΈλ₯Ό 1μ°¨μ λ°°μ΄μ μ μ₯νλ©΄ ꡬνν λ λ κΉλν κ²λλ€.
μμ€μ½λ
<Python>
n = int(input())
x = [-1e9] + sorted(map(int, input().split())) + [1e9]
vst = [False] * (n + 1)
ans = 0
while True:
tmp = []
for i in range(1,n+1):
if vst[i]: continue
p = q = i
while q <= n and x[q] - x[q - 1] > x[q + 1] - x[q] and not vst[q + 1]:
q += 1
while 0 < p and x[p] - x[p - 1] <= x[p + 1] - x[p] and not vst[q - 1]:
p -= 1
tmp.append((i - p, p, i))
tmp.append((q - i, i, q))
if not tmp: break
tmp.sort()
_, l, r = tmp[-1]
for i in range(l, r+1):
vst[i - 1] = True
ans += 1
print(ans)Last updated
Was this helpful?