結果
| 問題 |
No.2221 Set X
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:48:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,306 bytes |
| コンパイル時間 | 200 ms |
| コンパイル使用メモリ | 82,096 KB |
| 実行使用メモリ | 259,804 KB |
| 最終ジャッジ日時 | 2025-03-31 17:49:40 |
| 合計ジャッジ時間 | 25,140 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 21 |
ソースコード
import sys
def main():
input = sys.stdin.read().split()
N = int(input[0])
A = list(map(int, input[1:N+1]))
max_A = A[-1]
def compute_f(X):
if X == 0:
return float('inf')
prev = A[0] // X
count = 1
for a in A[1:]:
current = a // X
if current != prev:
count += 1
prev = current
return (X + 1) * count
# Binary search in [1, max_A]
low = 1
high = max_A
while low < high:
mid = (low + high) // 2
if compute_f(mid) < compute_f(mid + 1):
high = mid
else:
low = mid + 1
X_candidate = low
# Generate candidates around X_candidate, max_A, and max_A + 1
candidates = set()
start = max(1, X_candidate - 200)
end = min(max_A + 1, X_candidate + 200)
for x in range(start, end + 1):
candidates.add(x)
candidates.add(max_A)
candidates.add(max_A + 1)
# Check all candidates and find the minimal
min_f = None
best_x = None
for x in sorted(candidates):
fx = compute_f(x)
if min_f is None or fx < min_f or (fx == min_f and x < best_x):
min_f = fx
best_x = x
print(best_x)
print(min_f)
if __name__ == "__main__":
main()
lam6er