結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー みここみここ
提出日時 2022-12-14 03:30:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,268 ms / 4,000 ms
コード長 1,104 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 70,656 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-25 09:35:36
合計ジャッジ時間 6,709 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,552 KB
testcase_01 AC 5 ms
7,552 KB
testcase_02 AC 5 ms
7,552 KB
testcase_03 AC 6 ms
7,680 KB
testcase_04 AC 6 ms
7,552 KB
testcase_05 AC 6 ms
7,424 KB
testcase_06 AC 6 ms
7,552 KB
testcase_07 AC 6 ms
7,424 KB
testcase_08 AC 27 ms
7,552 KB
testcase_09 AC 32 ms
7,680 KB
testcase_10 AC 35 ms
7,552 KB
testcase_11 AC 47 ms
7,680 KB
testcase_12 AC 38 ms
7,680 KB
testcase_13 AC 471 ms
7,552 KB
testcase_14 AC 350 ms
7,552 KB
testcase_15 AC 635 ms
7,552 KB
testcase_16 AC 658 ms
7,552 KB
testcase_17 AC 566 ms
7,552 KB
testcase_18 AC 456 ms
7,552 KB
testcase_19 AC 597 ms
7,424 KB
testcase_20 AC 1,268 ms
7,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;

const int M = 200000;

int main()
{
    int n;
    cin >> n;
    bool b[200005]{0};
    int d[200005]{0};
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        b[a] = true;
        d[a] = a;
    }
    ll c[200005], s[200005];
    c[0] = s[0] = 0;
    for (int i = 1; i <= M + 1; i++)
    {
        c[i] = c[i - 1] + b[i - 1];
        s[i] = s[i - 1] + d[i - 1];
    }
    ll ans = 0;
    ll e = 0;
    for (int i = 1; i <= M; i++)
    {
        if (b[i])
        {
            ans += i * (n - e - 1);
            e++;
        }
    }
    for (int i = M; i > 0; i--)
    {
        if (!b[i])
        {
            continue;
        }
        ll r = i;
        for (int j = 2; j * j <= i; j++)
        {
            ll l = i / j + 1;
            ans -= -(s[r] - s[l]) * (j - 1) + (c[r] - c[l]) * (i % l + l * (j - 1));
            r = l;
        }
        for (int j = 1; j < r; j++)
        {
            if (b[j])
            {
                ans -= i % j;
            }
        }
    }
    cout << ans << endl;
}
0