結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー みここみここ
提出日時 2022-12-14 03:29:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,107 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 70,912 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-25 09:34:39
合計ジャッジ時間 4,843 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,808 KB
testcase_01 AC 5 ms
7,552 KB
testcase_02 AC 5 ms
7,552 KB
testcase_03 AC 6 ms
7,808 KB
testcase_04 AC 6 ms
7,808 KB
testcase_05 AC 6 ms
7,808 KB
testcase_06 AC 6 ms
7,552 KB
testcase_07 AC 6 ms
7,552 KB
testcase_08 AC 17 ms
7,552 KB
testcase_09 AC 19 ms
7,680 KB
testcase_10 AC 21 ms
7,680 KB
testcase_11 AC 27 ms
7,552 KB
testcase_12 AC 24 ms
7,680 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    int 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;
        }
        int r = i;
        for (int j = 2; j * j <= i; j++)
        {
            int 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