結果
| 問題 |
No.2221 Set X
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:22:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,177 bytes |
| コンパイル時間 | 193 ms |
| コンパイル使用メモリ | 82,260 KB |
| 実行使用メモリ | 67,816 KB |
| 最終ジャッジ日時 | 2025-04-15 21:28:03 |
| 合計ジャッジ時間 | 4,932 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 1 -- * 26 |
ソースコード
import math
def main():
import sys
input = sys.stdin.read
data = input().split()
N = int(data[0])
A = list(map(int, data[1:N+1]))
A = sorted(A)
candidates = set()
candidates.add(1)
candidates.add(A[-1] + 1)
for a in A:
if a == 0:
continue
max_k = int(math.isqrt(a)) + 1
for k in range(1, max_k + 1):
x1 = a // k
candidates.add(x1)
x2 = (a + k - 1) // k
candidates.add(x2)
for i in range(N-1):
d = A[i+1] - A[i]
for x in range(1, d + 1):
candidates.add(x)
candidates = sorted(candidates)
min_f = float('inf')
best_x = -1
for x in candidates:
if x <= 0:
continue
prev = -1
count = 0
for a in A:
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)
if __name__ == '__main__':
main()
lam6er