結果

問題 No.2221 Set X
ユーザー titia
提出日時 2023-02-19 00:53:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 786 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 81,980 KB
実行使用メモリ 88,984 KB
最終ジャッジ日時 2024-07-20 06:45:55
合計ジャッジ時間 6,915 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

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

    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

    

print(IND)
print(ANS)
0