結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー 👑 NachiaNachia
提出日時 2022-08-19 21:28:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 4,000 ms
コード長 756 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 75,308 KB
実行使用メモリ 8,852 KB
最終ジャッジ日時 2023-08-22 11:39:21
合計ジャッジ時間 2,394 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,396 KB
testcase_01 AC 15 ms
7,396 KB
testcase_02 AC 15 ms
7,608 KB
testcase_03 AC 15 ms
7,440 KB
testcase_04 AC 15 ms
7,484 KB
testcase_05 AC 15 ms
7,460 KB
testcase_06 AC 15 ms
7,424 KB
testcase_07 AC 15 ms
7,476 KB
testcase_08 AC 16 ms
8,012 KB
testcase_09 AC 16 ms
8,304 KB
testcase_10 AC 17 ms
8,000 KB
testcase_11 AC 18 ms
8,044 KB
testcase_12 AC 17 ms
8,012 KB
testcase_13 AC 43 ms
8,304 KB
testcase_14 AC 36 ms
8,360 KB
testcase_15 AC 52 ms
8,428 KB
testcase_16 AC 53 ms
8,512 KB
testcase_17 AC 47 ms
8,448 KB
testcase_18 AC 49 ms
7,808 KB
testcase_19 AC 50 ms
8,536 KB
testcase_20 AC 85 ms
8,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://yukicoder.me/problems/no/1233
#include<iostream>
#include<algorithm>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;
int A[200000];
LL C[200001]={};
LL SC[200001]={};
LL SCC[200001]={};

int main(){
 cin>>N;
 rep(i,N) cin>>A[i];
 sort(A,A+N);
 rep(i,N) C[A[i]]++;
 rep(i,200000) SC[i+1]=SC[i]+C[i+1];
 rep(i,200001) SCC[i]=i*C[i];
 rep(i,200000) SCC[i+1]+=SCC[i];

 LL ans=0;
 for(int i=1; i<=200000; i++){
  for(int j=0; j<=200000; j+=i){
   LL tmp = SCC[min(j+i-1,200000)] - SCC[j];
   tmp -= (SC[min(j+i-1,200000)] - SC[j]) * j;
   tmp *= C[i];
   ans += tmp;
  }
 }

 LL ans2=0;
 rep(i,N) ans2+=(LL)A[i]*(N-1-i);
 ans = ans2*2-ans;

 cout<<ans<<endl;

 return 0;
}
0