結果

問題 No.609 Noelちゃんと星々
ユーザー Mr.FukuMr.Fuku
提出日時 2018-08-04 18:52:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 935 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 21,224 KB
最終ジャッジ日時 2023-10-19 21:54:51
合計ジャッジ時間 16,693 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 656 ms
18,404 KB
testcase_01 AC 369 ms
14,256 KB
testcase_02 AC 264 ms
12,792 KB
testcase_03 AC 327 ms
13,964 KB
testcase_04 AC 186 ms
11,908 KB
testcase_05 AC 891 ms
20,488 KB
testcase_06 AC 760 ms
19,180 KB
testcase_07 AC 446 ms
15,412 KB
testcase_08 AC 110 ms
11,268 KB
testcase_09 AC 281 ms
13,348 KB
testcase_10 AC 576 ms
16,588 KB
testcase_11 AC 531 ms
16,172 KB
testcase_12 AC 600 ms
18,012 KB
testcase_13 AC 145 ms
11,480 KB
testcase_14 AC 73 ms
10,752 KB
testcase_15 AC 766 ms
19,180 KB
testcase_16 AC 858 ms
20,696 KB
testcase_17 AC 664 ms
18,424 KB
testcase_18 AC 245 ms
12,752 KB
testcase_19 AC 759 ms
19,180 KB
testcase_20 AC 934 ms
21,224 KB
testcase_21 AC 935 ms
21,224 KB
testcase_22 AC 929 ms
21,224 KB
testcase_23 AC 903 ms
21,224 KB
testcase_24 AC 933 ms
21,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
num = list(map(int,input().split()))
max_n,min_n = num[0],num[0]
step = [[-1,1]]

def measure(index,limit):
    cost = 0
    for i in range(n):
        cost += abs(num[i]-index)
        if cost>limit:
            return float("inf")
    return cost

for i in range(n):
    if max_n<num[i]:
        max_n=num[i]
    elif min_n>num[i]:
        min_n=num[i]

x = 2
while x<max_n-min_n:
    step.insert(0,[-x,x])
    x *= 2

index = (max_n+min_n)//2
cost = measure(index,float("inf"))
for s in step:
    for i in s:
        c = measure(index+i,cost)
        if cost>c:
            index += i
            cost = c
            break

print(cost)
0