結果
問題 | No.2221 Set X |
ユーザー |
![]() |
提出日時 | 2025-06-12 19:54:06 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,170 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 82,528 KB |
実行使用メモリ | 92,720 KB |
最終ジャッジ日時 | 2025-06-12 19:55:09 |
合計ジャッジ時間 | 5,035 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 TLE * 1 -- * 26 |
ソースコード
import math def main(): import sys input = sys.stdin.read().split() N = int(input[0]) A = list(map(int, input[1:N+1])) if N == 0: print(0) print(0) return max_A = A[-1] candidates = set() for a in A: candidates.add(a) k = int(math.sqrt(a)) candidates.add(k) candidates.add(k + 1) for i in range(1, N): diff = A[i] - A[i-1] candidates.add(diff) candidates.add(1) candidates.add(max_A) candidates.add(max_A + 1) candidates.add(int(math.sqrt(max_A))) candidates.add(int(math.sqrt(max_A)) + 1) candidates = sorted(candidates) min_f = float('inf') min_x = 0 for x in candidates: if x <= 0: continue count = 0 prev = -1 for a in A: current = a // x if current != prev: count += 1 prev = current f = (x + 1) * count if f < min_f or (f == min_f and x < min_x): min_f = f min_x = x print(min_x) print(min_f) if __name__ == "__main__": main()