結果

問題 No.838 Noelちゃんと星々3
ユーザー buey_tbuey_t
提出日時 2023-04-28 13:00:04
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,552 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 97,752 KB
最終ジャッジ日時 2023-08-11 01:39:05
合計ジャッジ時間 8,567 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 219 ms
82,792 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 222 ms
82,656 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 221 ms
82,712 KB
testcase_17 AC 221 ms
82,664 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 223 ms
82,596 KB
testcase_21 AC 219 ms
82,548 KB
testcase_22 AC 221 ms
82,692 KB
testcase_23 AC 221 ms
82,664 KB
testcase_24 AC 222 ms
82,836 KB
testcase_25 AC 218 ms
82,764 KB
testcase_26 AC 219 ms
82,764 KB
testcase_27 AC 218 ms
82,768 KB
testcase_28 AC 219 ms
82,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from random import randrange
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
import sys
input = sys.stdin.readline
# .rstrip()
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353

#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!


'''
二分探索の可能性はある
ソートしていい感じにやりたいけど
動かさないといけないので、厄介
動かすか、他を動かしてくるかという
貪欲でいけるんかな
いけそう
'''

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

Y.sort()

f = 0
ans = 0
for i in range(N):
    if f == 0:
        ans += abs(Y[i+1]-Y[i])
        f = 1
    elif f == 1:
        f = 2
    else:
        if i == N-1:
            ans += abs(Y[i]-Y[i-1])
            break
        if i == N-2:
            ans += abs(Y[i+1]-Y[i])
            break
        
        if abs(Y[i]-Y[i-1]) < abs(Y[i+1]-Y[i]):
            ans += abs(Y[i]-Y[i-1])
            f = 0
        else:
            ans += abs(Y[i+1]-Y[i])
            f = 1

print(ans)
























0