結果

問題 No.1233 割り切れない気持ち
ユーザー YamaKasaYamaKasa
提出日時 2020-09-19 17:44:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 3,153 ms
コード長 1,506 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 169,712 KB
実行使用メモリ 17,448 KB
最終ジャッジ日時 2023-09-05 22:48:33
合計ジャッジ時間 5,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,960 KB
testcase_01 AC 3 ms
4,952 KB
testcase_02 AC 4 ms
4,928 KB
testcase_03 AC 7 ms
4,992 KB
testcase_04 AC 6 ms
4,956 KB
testcase_05 AC 5 ms
4,900 KB
testcase_06 AC 5 ms
5,044 KB
testcase_07 AC 35 ms
7,416 KB
testcase_08 AC 59 ms
8,932 KB
testcase_09 AC 133 ms
12,536 KB
testcase_10 AC 146 ms
12,852 KB
testcase_11 AC 33 ms
7,212 KB
testcase_12 AC 184 ms
13,960 KB
testcase_13 AC 173 ms
13,996 KB
testcase_14 AC 175 ms
14,012 KB
testcase_15 AC 173 ms
13,980 KB
testcase_16 AC 164 ms
13,964 KB
testcase_17 AC 32 ms
6,460 KB
testcase_18 AC 127 ms
17,448 KB
testcase_19 AC 61 ms
6,448 KB
testcase_20 AC 32 ms
6,524 KB
testcase_21 AC 50 ms
6,480 KB
testcase_22 AC 48 ms
6,536 KB
testcase_23 AC 49 ms
6,664 KB
testcase_24 AC 49 ms
6,668 KB
testcase_25 AC 50 ms
6,492 KB
testcase_26 AC 50 ms
6,528 KB
testcase_27 AC 60 ms
7,552 KB
testcase_28 AC 59 ms
7,532 KB
testcase_29 AC 59 ms
7,148 KB
testcase_30 AC 57 ms
7,412 KB
testcase_31 AC 58 ms
7,048 KB
testcase_32 AC 58 ms
6,988 KB
testcase_33 AC 59 ms
6,976 KB
testcase_34 AC 58 ms
7,048 KB
testcase_35 AC 59 ms
6,932 KB
testcase_36 AC 57 ms
7,096 KB
testcase_37 AC 3 ms
5,220 KB
testcase_38 AC 32 ms
6,464 KB
testcase_39 AC 76 ms
12,700 KB
testcase_40 AC 78 ms
12,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const ll MAX = 200005;
ll b[MAX + 1]{};
ll c[MAX + 1]{};

int main() {
    int N;
    cin >> N;
    ll A[N];
    ll sum = 0;
    set<int> s;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        b[A[i]]++;
        s.insert(A[i]);
        sum += A[i];
    }
    
    for (int i = 1; i <= MAX; i++) {
        c[i] = c[i - 1] + b[i]; 
    }
    ll ans = sum * N;
    //cout << ans << "\n";
    for (ll i : s) {
        int t = i;
        if (i == 1) {
            ans -= b[1] * sum;
            continue;
        }
        //cout << "***********\n";
        //cout << i << "\n";
        for (ll k = 1; k < MAX; k++) {
            ll l = i * k - 1;
            ll r = min(MAX, i * (k + 1) - 1);
            if (l > MAX) break;
            //cout << l << " " << r << "\n";
            //cout << c[r + 1] - c[l + 1] << " " << b[i * k] << "\n";
            ll e = (c[r] - c[l]) * k * i * b[i];
            ans -= e;
            // if (e < 0) {
            //     cout << l << " " << r << "\n";
            //     cout << c[r] << " " << c[l] << "\n";
            //     cout << k << " aa\n";
            //     break;
            // }
            //cout << e << "\n";
        }
        //cout << ans << "\n";
    }
    cout << ans << "\n";
    // for (int i = 0; i < 100; i++) {
    //     cout << c[i] << "\n";
    // }
    // cout << "\n";
    // for (int i = 0; i < 10; i++) {
    //     cout << c[i] << " ";
    // }
    return 0;
}
0