結果
| 問題 |
No.2221 Set X
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 12:50:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,337 bytes |
| コンパイル時間 | 244 ms |
| コンパイル使用メモリ | 82,816 KB |
| 実行使用メモリ | 92,188 KB |
| 最終ジャッジ日時 | 2025-06-12 12:50:23 |
| 合計ジャッジ時間 | 7,394 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 1 -- * 21 |
ソースコード
import math
n = int(input())
A = list(map(int, input().split()))
A_1 = A[0]
A_N = A[-1]
# Generate candidate X values
candidates = set()
candidates.add(1)
candidates.add(A_N)
candidates.add(A_N + 1)
# Add candidates based on A_N
max_q = int(math.isqrt(A_N)) + 1
for q in range(1, max_q + 1):
x = A_N // q
candidates.add(x)
candidates.add(x - 1)
candidates.add(x + 1)
# Add candidates based on A_1 if it's non-zero
if A_1 > 0:
max_q_a1 = int(math.isqrt(A_1)) + 1
for q in range(1, max_q_a1 + 1):
x = A_1 // q
candidates.add(x)
candidates.add(x - 1)
candidates.add(x + 1)
# Filter valid X values
valid_x = []
for x in candidates:
if x > 0 and x <= A_N + 1:
valid_x.append(x)
valid_x = list(set(valid_x))
valid_x.sort()
# Function to count distinct quotients
def count_distinct_quotients(X):
if X == 0:
return 0
prev_q = A[0] // X
count = 1
for a in A[1:]:
q = a // X
if q != prev_q:
count += 1
prev_q = q
return count
# Find the minimum f(X)
min_f = float('inf')
best_x = None
for x in valid_x:
c = count_distinct_quotients(x)
current_f = (x + 1) * c
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)
gew1fw