結果

問題 No.2221 Set X
ユーザー とりゐ
提出日時 2023-02-17 22:01:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 85,120 KB
最終ジャッジ日時 2024-07-19 13:14:08
合計ジャッジ時間 22,963 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisors(n):
  lower,upper=[],[]
  i=1
  while i*i<=n:
    if n%i==0:
      lower.append(i)
      if i!=n//i:
        upper.append(n//i)
    i+=1
  return lower+upper[::-1]

def solve(a):
  ans=10**9
  ans2=-1
  kouho=list(range(1,500))+divisors(a[-1])
  kouho.sort()
  for x in kouho:
    last=-1
    cnt=0
    for i in a:
      if i//x!=last:
        cnt+=1
        last=i//x
    if ans>cnt*(x+1):
      ans=cnt*(x+1)
      ans2=x
  
  return ans,ans2

n=int(input())
a=list(map(int,input().split()))
ans,ans2=solve(a)
print(ans2)
print(ans)
0