結果

問題 No.2221 Set X
ユーザー gew1fw
提出日時 2025-06-12 21:16:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,372 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 82,016 KB
実行使用メモリ 103,268 KB
最終ジャッジ日時 2025-06-12 21:17:03
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    A = list(map(int, input[1:N+1]))
    A.sort()
    
    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
    
    max_A = A[-1]
    candidates = set()
    for dx in [-2, -1, 0, 1, 2]:
        x = max_A + dx
        if x >= 1:
            candidates.add(x)
    
    # Add some small X candidates
    for x in [1, 2, 3, 4, 5]:
        candidates.add(x)
    
    min_f = float('inf')
    best_X = None
    
    for x in candidates:
        current_f = compute_f(x)
        if current_f < min_f:
            min_f = current_f
            best_X = x
        elif current_f == min_f:
            if x < best_X:
                best_X = x
    
    # Additionally, check X = max_A + 1 if not already in candidates
    x = max_A + 1
    if x >= 1:
        candidates.add(x)
        current_f = compute_f(x)
        if current_f < min_f:
            min_f = current_f
            best_X = x
        elif current_f == min_f:
            if x < best_X:
                best_X = x
    
    print(best_X)
    print(min_f)

if __name__ == '__main__':
    main()
0