結果
問題 |
No.3268 As Seen in Toasters
|
ユーザー |
![]() |
提出日時 | 2025-09-13 02:41:30 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 488 ms / 2,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 430 ms |
コンパイル使用メモリ | 12,032 KB |
実行使用メモリ | 32,884 KB |
最終ジャッジ日時 | 2025-09-13 02:41:43 |
合計ジャッジ時間 | 11,862 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) A.sort() def calc(x,y): if x<0 and y<0: return -x-y else: return abs(x-y) def calc2(A): score=0 for i in range(N-1): x,y=A[i],A[i+1] score+=calc(x,y) return score MIN=calc2(A) ind=A[:] MINUS=[] OTHER=[] for a in A: if a<0: MINUS.append(a) else: OTHER.append(a) B=[-1]*len(OTHER) f=0 l=len(B)-1 for i in range(len(OTHER)): if i%2==0: B[f]=OTHER[i] f+=1 else: B[l]=OTHER[i] l-=1 if MINUS: B=[MINUS[0]]+B+MINUS[1:][::-1] score2=calc2(B) if score2<MIN: MIN=score2 ind=B[:] print(MIN)