結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー 👑 rin204rin204
提出日時 2022-08-19 21:58:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 4,000 ms
コード長 506 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 110,572 KB
最終ジャッジ日時 2023-08-22 11:40:16
合計ジャッジ時間 3,624 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,348 KB
testcase_01 AC 71 ms
71,184 KB
testcase_02 AC 70 ms
71,272 KB
testcase_03 AC 83 ms
76,400 KB
testcase_04 AC 80 ms
76,348 KB
testcase_05 AC 83 ms
76,280 KB
testcase_06 AC 83 ms
76,552 KB
testcase_07 AC 84 ms
76,548 KB
testcase_08 AC 88 ms
78,000 KB
testcase_09 AC 88 ms
78,136 KB
testcase_10 AC 90 ms
78,084 KB
testcase_11 AC 92 ms
78,276 KB
testcase_12 AC 91 ms
78,380 KB
testcase_13 AC 128 ms
89,340 KB
testcase_14 AC 118 ms
86,056 KB
testcase_15 AC 142 ms
94,584 KB
testcase_16 AC 143 ms
94,896 KB
testcase_17 AC 134 ms
93,308 KB
testcase_18 AC 132 ms
91,936 KB
testcase_19 AC 136 ms
93,180 KB
testcase_20 AC 192 ms
110,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
ma = max(A) + 1
cnt = [0] * ma
for a in A:
    cnt[a] += 1
A.sort()
for i in range(ma - 1):
    cnt[i + 1] += cnt[i]
plus = 0
minus = 0
tot = sum(A)
for i, a in enumerate(A):
    plus += a * (n - i - 1)
    minus += tot
    tot -= a
    for j in range(a, ma, a):
        if j + a < ma:
            c = cnt[j + a - 1] - cnt[j - 1]
            minus -= c * j
        else:
            c = n - cnt[j - 1]
            minus -= c * j
    
print(plus - minus)
0