結果

問題 No.1233 割り切れない気持ち
ユーザー satashunsatashun
提出日時 2020-09-18 21:46:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 3,153 ms
コード長 2,371 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 204,012 KB
実行使用メモリ 7,924 KB
最終ジャッジ日時 2023-09-04 21:44:12
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,960 KB
testcase_01 AC 5 ms
7,108 KB
testcase_02 AC 8 ms
7,028 KB
testcase_03 AC 10 ms
6,960 KB
testcase_04 AC 9 ms
7,256 KB
testcase_05 AC 7 ms
7,252 KB
testcase_06 AC 8 ms
7,004 KB
testcase_07 AC 28 ms
7,340 KB
testcase_08 AC 42 ms
7,324 KB
testcase_09 AC 68 ms
7,600 KB
testcase_10 AC 72 ms
7,488 KB
testcase_11 AC 26 ms
6,952 KB
testcase_12 AC 81 ms
7,744 KB
testcase_13 AC 81 ms
7,844 KB
testcase_14 AC 82 ms
7,772 KB
testcase_15 AC 82 ms
7,816 KB
testcase_16 AC 82 ms
7,840 KB
testcase_17 AC 34 ms
7,864 KB
testcase_18 AC 71 ms
7,816 KB
testcase_19 AC 64 ms
7,808 KB
testcase_20 AC 35 ms
7,864 KB
testcase_21 AC 51 ms
7,776 KB
testcase_22 AC 51 ms
7,816 KB
testcase_23 AC 51 ms
7,800 KB
testcase_24 AC 51 ms
7,924 KB
testcase_25 AC 51 ms
7,820 KB
testcase_26 AC 51 ms
7,844 KB
testcase_27 AC 59 ms
7,900 KB
testcase_28 AC 60 ms
7,844 KB
testcase_29 AC 59 ms
7,912 KB
testcase_30 AC 59 ms
7,812 KB
testcase_31 AC 59 ms
7,748 KB
testcase_32 AC 59 ms
7,812 KB
testcase_33 AC 59 ms
7,772 KB
testcase_34 AC 59 ms
7,808 KB
testcase_35 AC 59 ms
7,764 KB
testcase_36 AC 60 ms
7,740 KB
testcase_37 AC 5 ms
7,048 KB
testcase_38 AC 35 ms
7,840 KB
testcase_39 AC 54 ms
7,768 KB
testcase_40 AC 53 ms
7,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const int MX = 200010;

int main() {
    int N;
    cin >> N;
    V<int> A(N);
    rep(i, N) cin >> A[i];
    sort(ALL(A));

    V<int> cnt(MX);
    V<ll> csum(MX), psum(MX);
    rep(i, N) cnt[A[i]]++;
    rep(i, MX - 1) {
        csum[i + 1] = csum[i] + cnt[i];
        psum[i + 1] = psum[i] + cnt[i] * ll(i);
    }

    ll ans = 0;

    for (int i = 1; i < MX; ++i) {
        if (!cnt[i]) continue;
        for (int j = i; j < MX; j += i) {
            ll a = psum[min(MX - 1, j + i)] - psum[j] -
                   j * (csum[min(MX - 1, j + i)] - csum[j]);
            ans += a * cnt[i];
        }
    }

    int s = 0;

    for (int i = N - 1; i >= 0;) {
        int j = i;
        while (j >= 0 && A[j] == A[i]) --j;
        ans += (ll)A[i] * s * (i - j);
        s += (i - j);
        i = j;
    }

    cout << ans << endl;

    return 0;
}
0