結果

問題 No.837 Noelちゃんと星々2
ユーザー vwxyzvwxyz
提出日時 2024-04-07 20:21:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 1,820 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 24,336 KB
最終ジャッジ日時 2024-04-07 20:21:15
合計ジャッジ時間 7,240 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 468 ms
24,328 KB
testcase_01 AC 475 ms
24,320 KB
testcase_02 AC 442 ms
24,336 KB
testcase_03 AC 449 ms
24,336 KB
testcase_04 AC 466 ms
24,328 KB
testcase_05 AC 442 ms
24,324 KB
testcase_06 AC 473 ms
24,320 KB
testcase_07 AC 445 ms
24,324 KB
testcase_08 AC 439 ms
24,328 KB
testcase_09 AC 29 ms
10,240 KB
testcase_10 AC 29 ms
10,240 KB
testcase_11 AC 29 ms
10,240 KB
testcase_12 AC 29 ms
10,240 KB
testcase_13 AC 29 ms
10,240 KB
testcase_14 AC 29 ms
10,240 KB
testcase_15 AC 28 ms
10,240 KB
testcase_16 AC 31 ms
10,240 KB
testcase_17 AC 29 ms
10,240 KB
testcase_18 AC 28 ms
10,240 KB
testcase_19 AC 30 ms
10,240 KB
testcase_20 AC 31 ms
10,240 KB
testcase_21 AC 29 ms
10,240 KB
testcase_22 AC 29 ms
10,240 KB
testcase_23 AC 29 ms
10,240 KB
testcase_24 AC 29 ms
10,240 KB
testcase_25 AC 30 ms
10,240 KB
testcase_26 AC 29 ms
10,240 KB
testcase_27 AC 28 ms
10,240 KB
testcase_28 AC 29 ms
10,240 KB
testcase_29 AC 29 ms
10,240 KB
testcase_30 AC 30 ms
10,240 KB
testcase_31 AC 29 ms
10,240 KB
testcase_32 AC 30 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Cumsum:
    def __init__(self,lst,mod=0):
        self.N=len(lst)
        self.mod=mod
        self.cumsum=[0]*(self.N+1)
        self.cumsum[0]=0
        for i in range(1,self.N+1):
            self.cumsum[i]=self.cumsum[i-1]+lst[i-1]
            if self.mod:
                self.cumsum[i]%=self.mod

    def __getitem__(self,i):
        if type(i)==int:
            if 0<=i<self.N:
                a,b=i,i+1
            elif -self.N<=i<0:
                a,b=i+self.N,i+self.N+1
            else:
                raise IndexError('list index out of range')
        else:
            a,b=i.start,i.stop
            if a==None or a<-self.N:
                a=0
            elif self.N<=a:
                a=self.N
            elif a<0:
                a+=self.N
            if b==None or self.N<=b:
                b=self.N
            elif b<-self.N:
                b=0
            elif b<0:
                b+=self.N
        s=self.cumsum[b]-self.cumsum[a]
        if self.mod:
            s%=self.mod
        return s

    def __setitem__(self,i,x):
        if -self.N<=i<0:
            i+=self.N
        elif not 0<=i<self.N:
            raise IndexError('list index out of range')
        self.cumsum[i+1]=self.cumsum[i]+x
        if self.mod:
            self.cumsum[i+1]%=self.mod

    def __len__(self):
        return self.N

    def __str__(self):
        lst=[self.cumsum[i+1]-self.cumsum[i] for i in range(self.N)]
        if self.mod:
            for i in range(self.N):
                lst[i]%=self.mod
        return "["+", ".join(map(str,lst))+"]"

N=int(input())
Y=list(map(int,input().split()))
Y.sort()
Y=Cumsum(Y)
ans=1<<60
for i in range(N+1):
    le0=i//2
    s0=Y[i-le0:i]-Y[:le0]
    le1=(N-i)//2
    s1=Y[N-le1:N]-Y[i:i+le1]
    ans=min(ans,s0+s1)
if len(set(Y))==1:
    ans=1
print(ans)
0