結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー t98slidert98slider
提出日時 2022-08-24 09:32:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 4,000 ms
コード長 659 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 165,480 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-08-22 11:54:10
合計ジャッジ時間 2,843 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,128 KB
testcase_01 AC 5 ms
6,152 KB
testcase_02 AC 6 ms
6,504 KB
testcase_03 AC 11 ms
6,168 KB
testcase_04 AC 8 ms
6,200 KB
testcase_05 AC 10 ms
6,172 KB
testcase_06 AC 9 ms
6,176 KB
testcase_07 AC 10 ms
6,208 KB
testcase_08 AC 5 ms
6,156 KB
testcase_09 AC 6 ms
6,200 KB
testcase_10 AC 5 ms
6,176 KB
testcase_11 AC 6 ms
6,196 KB
testcase_12 AC 6 ms
6,300 KB
testcase_13 AC 32 ms
6,276 KB
testcase_14 AC 26 ms
6,124 KB
testcase_15 AC 42 ms
6,168 KB
testcase_16 AC 44 ms
6,324 KB
testcase_17 AC 37 ms
6,264 KB
testcase_18 AC 41 ms
6,268 KB
testcase_19 AC 40 ms
6,200 KB
testcase_20 AC 73 ms
6,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n, v, r = 200000;
    cin >> n;
    vector<ll> cnt(r + 2), s(r + 2);
    for(int i = 0; i < n; i++){
        cin >> v;
        cnt[v + 1]++;
        s[v + 1] += v;
    }
    for(int i = 0; i <= r; i++){
        cnt[i + 1] += cnt[i];
        s[i + 1] += s[i];
    }
    ll ans = 0;
    for(int i = 1; i <= r; i++){
        if(cnt[i + 1] == cnt[i])continue;
        ans += (cnt[r + 1] - cnt[i + 1]) * i;
        for(int j = i; j <= r; j+=i){
            ans -= s[min(r + 1, j + i)] - s[j] - (cnt[min(r + 1, j + i)] - cnt[j]) * j;
        }
    }
    cout << ans << '\n';
}
0