結果
問題 |
No.2221 Set X
|
ユーザー |
![]() |
提出日時 | 2025-06-12 20:54:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,651 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 261,504 KB |
最終ジャッジ日時 | 2025-06-12 20:58:25 |
合計ジャッジ時間 | 15,966 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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])) A.sort() max_A = A[-1] if N > 0 else 0 candidate1_x = max_A + 1 candidate1_f = (max_A + 1) + 1 # (X+1)*1 where X = max_A + 1 def compute_f(X): if X == 0: return float('inf') count = 1 prev = A[0] // X for a in A[1:]: current = a // X if current != prev: count += 1 prev = current return (X + 1) * count low = 1 high = max_A for _ in range(100): if high < low: break mid1 = low + (high - low) // 3 mid2 = high - (high - low) // 3 f1 = compute_f(mid1) f2 = compute_f(mid2) if f1 < f2: high = mid2 - 1 else: low = mid1 + 1 min_f = float('inf') best_x = None start = max(low - 100, 1) end = min(high + 100, max_A) for X in range(start, end + 1): current_f = compute_f(X) if current_f < min_f or (current_f == min_f and (best_x is None or X < best_x)): min_f = current_f best_x = X if best_x is None: best_x = candidate1_x min_f = candidate1_f if candidate1_f < min_f: print(candidate1_x) print(candidate1_f) elif candidate1_f == min_f: if candidate1_x < best_x: print(candidate1_x) print(candidate1_f) else: print(best_x) print(min_f) else: print(best_x) print(min_f) if __name__ == "__main__": main()