結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー 👑 KazunKazun
提出日時 2022-08-19 22:38:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 4,000 ms
コード長 574 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 110,816 KB
最終ジャッジ日時 2023-08-22 11:44:32
合計ジャッジ時間 3,720 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,596 KB
testcase_01 AC 74 ms
71,308 KB
testcase_02 AC 74 ms
71,300 KB
testcase_03 AC 83 ms
76,504 KB
testcase_04 AC 87 ms
76,300 KB
testcase_05 AC 83 ms
76,400 KB
testcase_06 AC 82 ms
76,216 KB
testcase_07 AC 84 ms
76,224 KB
testcase_08 AC 92 ms
78,164 KB
testcase_09 AC 93 ms
78,364 KB
testcase_10 AC 92 ms
78,004 KB
testcase_11 AC 96 ms
78,180 KB
testcase_12 AC 94 ms
78,160 KB
testcase_13 AC 133 ms
89,320 KB
testcase_14 AC 125 ms
86,652 KB
testcase_15 AC 155 ms
95,280 KB
testcase_16 AC 152 ms
94,984 KB
testcase_17 AC 142 ms
92,976 KB
testcase_18 AC 134 ms
91,928 KB
testcase_19 AC 143 ms
92,912 KB
testcase_20 AC 192 ms
110,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N=int(input())
    A=list(map(int,input().split()))
    A.sort()

    X=0
    for i in range(N):
        X+=(N-1-2*i)*A[i]

    A_max=max(A)
    T=[0]*(A_max+1)
    for a in A:
        T[a]=1

    for k in range(1,A_max+1):
        T[k]+=T[k-1]

    Y=0
    for k in range(1,A_max):
        if T[k]-T[k-1]==1:
            for p in range(1,A_max//k+1):
                left =max(1, p*k)
                right=min(A_max, (p+1)*k-1)

                Y+=k*p*(T[right]-T[left-1])
                if p==1:
                    Y-=k

    return X+Y

print(solve())
0