結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー 👑 rin204rin204
提出日時 2022-08-19 21:58:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 178 ms / 4,000 ms
コード長 506 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 110,080 KB
最終ジャッジ日時 2024-05-09 17:20:35
合計ジャッジ時間 3,119 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 42 ms
51,840 KB
testcase_02 AC 43 ms
52,096 KB
testcase_03 AC 60 ms
61,952 KB
testcase_04 AC 57 ms
61,568 KB
testcase_05 AC 59 ms
61,440 KB
testcase_06 AC 62 ms
61,312 KB
testcase_07 AC 57 ms
61,696 KB
testcase_08 AC 65 ms
65,536 KB
testcase_09 AC 66 ms
66,048 KB
testcase_10 AC 66 ms
66,304 KB
testcase_11 AC 67 ms
66,944 KB
testcase_12 AC 65 ms
66,176 KB
testcase_13 AC 108 ms
85,632 KB
testcase_14 AC 95 ms
80,768 KB
testcase_15 AC 126 ms
93,952 KB
testcase_16 AC 130 ms
93,952 KB
testcase_17 AC 120 ms
91,776 KB
testcase_18 AC 121 ms
91,008 KB
testcase_19 AC 121 ms
91,904 KB
testcase_20 AC 178 ms
110,080 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