結果

問題 No.2221 Set X
ユーザー lam6er
提出日時 2025-04-15 21:14:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,045 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 75,656 KB
最終ジャッジ日時 2025-04-15 21:21:42
合計ジャッジ時間 15,714 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 TLE * 3 -- * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    n = int(input[0])
    A = list(map(int, input[1:n+1]))
    max_A = A[-1]
    min_product = float('inf')
    best_X = 0

    # Iterate X up to 200000 (chosen as a reasonable limit)
    for X in range(1, 200001):
        prev = A[0] // X
        cnt = 1
        for a in A[1:]:
            current = a // X
            if current != prev:
                cnt += 1
                prev = current
        product = (X + 1) * cnt
        if product < min_product or (product == min_product and X < best_X):
            min_product = product
            best_X = X

    # Check X = max_A + 1
    X = max_A + 1
    cnt = 1
    for a in A:
        if a > 0 and (a // X) != 0:
            cnt = 2  # if any element is non-zero, it's 0 and 1
            break
    product = (X + 1) * cnt
    if product < min_product or (product == min_product and X < best_X):
        min_product = product
        best_X = X

    print(best_X)
    print(min_product)

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