結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー hourenhouren
提出日時 2022-08-19 23:15:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 4,000 ms
コード長 1,095 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 166,468 KB
実行使用メモリ 7,880 KB
最終ジャッジ日時 2023-08-22 11:47:59
合計ジャッジ時間 2,930 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,788 KB
testcase_01 AC 17 ms
7,784 KB
testcase_02 AC 18 ms
7,824 KB
testcase_03 AC 17 ms
7,680 KB
testcase_04 AC 18 ms
7,684 KB
testcase_05 AC 17 ms
7,772 KB
testcase_06 AC 18 ms
7,772 KB
testcase_07 AC 17 ms
7,784 KB
testcase_08 AC 18 ms
7,776 KB
testcase_09 AC 18 ms
7,868 KB
testcase_10 AC 18 ms
7,736 KB
testcase_11 AC 18 ms
7,740 KB
testcase_12 AC 19 ms
7,776 KB
testcase_13 AC 29 ms
7,852 KB
testcase_14 AC 26 ms
7,676 KB
testcase_15 AC 32 ms
7,788 KB
testcase_16 AC 32 ms
7,812 KB
testcase_17 AC 30 ms
7,744 KB
testcase_18 AC 29 ms
7,848 KB
testcase_19 AC 31 ms
7,844 KB
testcase_20 AC 44 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
const int MAX = 200000;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> cnt(200200,0), tot(200200,0), sum(200200,0);
    rep(i,n){
        ll a;
        cin >> a;
        cnt[a]++, tot[a]++;
        sum[a] += a;
    }
    rep(i,MAX) tot[i+1] += tot[i], sum[i+1] += sum[i];
    ll ans = 0;
    for(int i=1;i<=MAX;i++){
        ans += (tot[MAX] - tot[i])*cnt[i] * i;
        for(int j=2;;j++){
            int x = min(i*j-1, MAX), y = i*(j-1);
            ll z = sum[x]-sum[y] - (tot[x]-tot[y])*y;
            z *= cnt[i];
            ans -= z;
            if(x==MAX) break;
        }
    }
    cout << ans << '\n';
    return 0;
}
0