結果
| 問題 |
No.3268 As Seen in Toasters
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-12 21:56:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 154 ms / 2,000 ms |
| コード長 | 927 bytes |
| コンパイル時間 | 541 ms |
| コンパイル使用メモリ | 82,456 KB |
| 実行使用メモリ | 107,272 KB |
| 最終ジャッジ日時 | 2025-09-12 23:38:17 |
| 合計ジャッジ時間 | 5,741 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
import sys
import os
IS_LOCAL = os.environ.get("LOCAL") == "true"
def debug(*args, sep=" ", end="\n", flush=False) -> None:
if IS_LOCAL:
print(*args, sep=sep, end=end, file=sys.stderr, flush=flush)
def yn(flg: bool) -> bool:
print('Yes' if flg else 'No')
return flg
def gcd(a, b):
a = abs(a); b = abs(b)
if a < b: a, b = b, a
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def main():
readline = sys.stdin.readline
def f(x, y):
if x < 0 and y < 0:
return -x - y
return abs(x - y)
N = int(input())
A = list(map(int, readline().split()))
A.sort()
ans = sum(f(A[i], A[i + 1]) for i in range(N - 1))
if A[1] < 0:
A.append(A.pop(0))
alt = sum(f(A[i], A[i + 1]) for i in range(N - 1))
ans = min(ans, alt)
print(ans)
if __name__ == "__main__":
main()