結果

問題 No.2221 Set X
ユーザー titia
提出日時 2023-02-19 01:06:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 783 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 90,496 KB
最終ジャッジ日時 2024-07-20 06:54:26
合計ジャッジ時間 17,611 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc(x):
    score=1
    for i in range(1,N):
        if A[i]//x!=A[i-1]//x:
            score+=1
    return score*(x+1)

def calc2(x):
    score=1
    now=A[0]//x
    OK=0
    
    while True:
        NG=len(A)

        while NG>OK+1:
            mid=(OK+NG)//2

            if A[mid]//x==now:
                OK=mid
            else:
                NG=mid

        if NG==len(A):
            break
        else:
            score+=1
            now=A[NG]//x
            OK=NG

        if score*(x+1)>=ANS:
            return 1<<100

    return score*(x+1)
        
    


N=int(input())
A=list(map(int,input().split()))

ANS=1<<100
IND=-1

for i in range(1,100):
    k=calc(i)

    if k<ANS:
        ANS=k
        IND=i

for i in range(100,ANS+1):
    k=calc2(i)

    if k<ANS:
        ANS=k
        IND=i
    if i>ANS:
        break

    

print(IND)
print(ANS)
0