結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー やうやう
提出日時 2022-08-19 23:19:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 4,000 ms
コード長 767 bytes
コンパイル時間 1,547 ms
コンパイル使用メモリ 170,232 KB
実行使用メモリ 6,248 KB
最終ジャッジ日時 2023-08-22 11:48:29
合計ジャッジ時間 3,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,104 KB
testcase_01 AC 6 ms
6,092 KB
testcase_02 AC 6 ms
6,168 KB
testcase_03 AC 6 ms
6,080 KB
testcase_04 AC 6 ms
6,088 KB
testcase_05 AC 6 ms
6,148 KB
testcase_06 AC 6 ms
6,152 KB
testcase_07 AC 6 ms
5,976 KB
testcase_08 AC 9 ms
5,984 KB
testcase_09 AC 10 ms
5,980 KB
testcase_10 AC 10 ms
6,208 KB
testcase_11 AC 12 ms
6,032 KB
testcase_12 AC 12 ms
5,988 KB
testcase_13 AC 108 ms
6,248 KB
testcase_14 AC 82 ms
6,148 KB
testcase_15 AC 154 ms
5,976 KB
testcase_16 AC 166 ms
6,032 KB
testcase_17 AC 132 ms
5,984 KB
testcase_18 AC 137 ms
6,120 KB
testcase_19 AC 126 ms
6,216 KB
testcase_20 AC 306 ms
5,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
using V=vector<ll>;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)

V a(200010,1e9),b(200010);

int src(ll x){
    int l=0,r=200005;
    while(l+1<r){
        int k=(l+r)/2;
        if(a[k]<x) l=k;
        else r=k;
    }
    return r;
}

int main(){
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    rep(i,n) b[i+1]=b[i]+a[i];

    ll ans=0;
    rep(i,n-1) ans+=a[i]*(n-i-1);
    rep(i,n-1){
        int l,r=i+1;
        for(ll j=1;a[i]*j<=a[n-1];j++){
            l=r;
            r=min(n,src(a[i]*(j+1)));
            ans-=b[r]-b[l]-a[i]*(r-l)*j;
        }
    }

    cout << ans << endl;

}
0