結果

問題 No.1233 割り切れない気持ち
ユーザー otogawa
提出日時 2025-04-22 05:09:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 273 ms / 3,153 ms
コード長 791 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 201,712 KB
実行使用メモリ 9,244 KB
最終ジャッジ日時 2025-04-22 05:09:50
合計ジャッジ時間 6,951 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int ll
using ll = long long;

const int MOD = 1e9 + 7;

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);

    int n; cin >> n;
    vector<int> a(n);
    for (auto &i : a) cin >> i;

    sort(a.begin(), a.end());

    vector suff = a;
    suff.push_back(0);
    for (int i = n - 1; i >= 0; i--) {
        suff[i] += suff[i + 1];
    }

    int ans = 0;
    for (int i = 0, j = 0; i < n; i = j) {
        while (j < n && a[i] == a[j]) j++;
        int l = 0;
        for (int k = 0; k*a[i] <= a[n - 1] && l < n; k++) {
            int r = lower_bound(a.begin(), a.end(), (k + 1)*a[i]) - a.begin();
            ans += ((suff[l] - suff[r]) - (r - l) * k * a[i]) * (j - i);
            l = r;
        }
    }

    cout << ans << endl;
}
0