結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-10 00:50:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 4,000 ms
コード長 755 bytes
コンパイル時間 1,109 ms
コンパイル使用メモリ 112,484 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-05-04 19:07:07
合計ジャッジ時間 3,210 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,168 KB
testcase_01 AC 6 ms
7,296 KB
testcase_02 AC 10 ms
7,296 KB
testcase_03 AC 19 ms
7,296 KB
testcase_04 AC 14 ms
7,168 KB
testcase_05 AC 19 ms
7,296 KB
testcase_06 AC 14 ms
7,296 KB
testcase_07 AC 19 ms
7,168 KB
testcase_08 AC 6 ms
7,296 KB
testcase_09 AC 7 ms
7,296 KB
testcase_10 AC 7 ms
7,168 KB
testcase_11 AC 7 ms
7,296 KB
testcase_12 AC 6 ms
7,168 KB
testcase_13 AC 40 ms
7,680 KB
testcase_14 AC 30 ms
7,680 KB
testcase_15 AC 53 ms
8,064 KB
testcase_16 AC 55 ms
7,936 KB
testcase_17 AC 47 ms
7,936 KB
testcase_18 AC 60 ms
8,064 KB
testcase_19 AC 49 ms
7,936 KB
testcase_20 AC 97 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    ll N, ans=0;
    cin >> N;
    vector<ll> A(N+1), S(5e5+1);
    for (int i=1; i<=N; i++){
        cin >> A[i];
        S[A[i]]++;
    }
    sort(A.begin(), A.end());
    for (int i=1; i<=5e5; i++) S[i] += S[i-1];

    for (int i=1; i<=N; i++) ans += (N-i*2+1) * A[i];

    for (ll i=1; i<=N; i++){
        for (ll j=A[i]; j<=2e5; j+=A[i]){
            ans += j/A[i] * (S[A[i]+j-1]-S[j-1]) * A[i];
        }
        ans -= A[i];
    }

    cout << ans << endl;

    return 0;
}
0