結果

問題 No.609 Noelちゃんと星々
ユーザー takakintakakin
提出日時 2020-05-24 20:51:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,341 ms / 2,000 ms
コード長 318 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,008 KB
最終ジャッジ日時 2024-04-20 10:41:53
合計ジャッジ時間 23,552 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,020 ms
18,944 KB
testcase_01 AC 524 ms
14,832 KB
testcase_02 AC 372 ms
13,516 KB
testcase_03 AC 490 ms
14,616 KB
testcase_04 AC 256 ms
12,500 KB
testcase_05 AC 1,264 ms
20,996 KB
testcase_06 AC 1,087 ms
19,600 KB
testcase_07 AC 655 ms
15,916 KB
testcase_08 AC 158 ms
11,904 KB
testcase_09 AC 424 ms
13,940 KB
testcase_10 AC 805 ms
17,148 KB
testcase_11 AC 754 ms
16,596 KB
testcase_12 AC 943 ms
18,412 KB
testcase_13 AC 198 ms
12,032 KB
testcase_14 AC 98 ms
11,264 KB
testcase_15 AC 1,118 ms
19,828 KB
testcase_16 AC 1,304 ms
21,332 KB
testcase_17 AC 1,021 ms
18,952 KB
testcase_18 AC 364 ms
13,480 KB
testcase_19 AC 1,080 ms
19,596 KB
testcase_20 AC 1,331 ms
21,752 KB
testcase_21 AC 1,328 ms
21,876 KB
testcase_22 AC 1,338 ms
22,008 KB
testcase_23 AC 1,341 ms
21,752 KB
testcase_24 AC 1,329 ms
21,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
Y=[int(i) for i in input().split()]

def f(x):
  ret=0
  for y in Y:
    ret+=abs(y-x)
  return ret

l,r=min(Y),max(Y)

while r-l>2:
  mid1,mid2=l+(r-l)//3,r-(r-l)//3
  if f(mid1)<=f(mid2):
    r=mid2
  else:
    l=mid1
print(min(f(l),f(l+1),f(r)))
0