結果

問題 No.1233 割り切れない気持ち
ユーザー satashunsatashun
提出日時 2020-09-18 21:44:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,367 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 206,244 KB
実行使用メモリ 8,100 KB
最終ジャッジ日時 2023-09-04 18:54:26
合計ジャッジ時間 5,938 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,012 KB
testcase_01 AC 5 ms
7,144 KB
testcase_02 AC 7 ms
7,144 KB
testcase_03 AC 10 ms
7,076 KB
testcase_04 AC 9 ms
7,016 KB
testcase_05 AC 8 ms
7,128 KB
testcase_06 AC 8 ms
7,020 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 36 ms
7,800 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 35 ms
7,924 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 5 ms
7,128 KB
testcase_38 AC 36 ms
7,752 KB
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

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 += A[i] * s * (i - j);
        s += (i - j);
        i = j;
    }

    cout << ans << endl;

    return 0;
}
0