結果
問題 |
No.2221 Set X
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:02:05 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,006 bytes |
コンパイル時間 | 342 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 92,080 KB |
最終ジャッジ日時 | 2025-06-12 18:02:12 |
合計ジャッジ時間 | 4,760 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 TLE * 1 -- * 26 |
ソースコード
import math n = int(input()) A = list(map(int, input().split())) A_sorted = sorted(A) max_A = A_sorted[-1] if n > 0 else 0 candidates = set() # Add X from 1 to sqrt(max_A) max_x_sqrt = int(math.isqrt(max_A)) if max_A > 0 else 0 for x in range(1, max_x_sqrt + 1): candidates.add(x) # Add candidates from each A_i for a in A_sorted: if a == 0: continue max_k = int(math.isqrt(a)) for k in range(1, max_k + 1): x1 = a // k if x1 <= max_A: candidates.add(x1) x2 = x1 + 1 if x2 <= max_A: candidates.add(x2) # Add X = max_A + 1 candidates.add(max_A + 1) min_f = float('inf') best_x = None for x in sorted(candidates): prev = None count = 0 for a in A_sorted: q = a // x if q != prev: count += 1 prev = q current_f = (x + 1) * count if current_f < min_f or (current_f == min_f and x < best_x): min_f = current_f best_x = x print(best_x) print(min_f)