結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー 沙耶花沙耶花
提出日時 2022-08-19 21:47:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 4,000 ms
コード長 945 bytes
コンパイル時間 4,163 ms
コンパイル使用メモリ 262,100 KB
実行使用メモリ 7,280 KB
最終ジャッジ日時 2023-08-22 11:40:04
合計ジャッジ時間 5,723 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,272 KB
testcase_01 AC 5 ms
6,232 KB
testcase_02 AC 5 ms
6,196 KB
testcase_03 AC 11 ms
6,188 KB
testcase_04 AC 9 ms
6,296 KB
testcase_05 AC 11 ms
6,288 KB
testcase_06 AC 10 ms
6,364 KB
testcase_07 AC 10 ms
6,308 KB
testcase_08 AC 6 ms
6,240 KB
testcase_09 AC 6 ms
6,272 KB
testcase_10 AC 6 ms
6,328 KB
testcase_11 AC 8 ms
6,280 KB
testcase_12 AC 7 ms
6,276 KB
testcase_13 AC 41 ms
6,940 KB
testcase_14 AC 32 ms
6,536 KB
testcase_15 AC 54 ms
6,824 KB
testcase_16 AC 55 ms
6,736 KB
testcase_17 AC 48 ms
6,836 KB
testcase_18 AC 52 ms
6,908 KB
testcase_19 AC 48 ms
6,788 KB
testcase_20 AC 100 ms
7,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main() {	
	
	int n;
	cin>>n;
	
	vector<long long> cnt(200005,0);
	vector<long long> sum(200005,0);
	vector<int> t;
	rep(i,n){
		int a;
		cin>>a;
		cnt[a]++;
		sum[a] += a;
		t.push_back(a);
	}
	
	rep(i,cnt.size()-1){
		cnt[i+1] += cnt[i];
		sum[i+1] += sum[i];
	}
	
	sort(t.begin(),t.end());
	
	long long ans = 0;
	rep(i,t.size()){
		long long ct = t.size()-1-i;
		ct *= t[i];
		ans += ct;
		
		for(int j=1;j<=5000000;j++){
			int l = t[i] * j;
			int r = l+t[i];
			r = min(r,200004);
			if(l>=200001)break;
			
			long long S = sum[r-1] - sum[l-1];
			long long C = cnt[r-1] - cnt[l-1];
			C *= j;
			C *= t[i];
			S -= C;
			ans -= S;
			
		}
		
	}
	cout<<ans<<endl;
	
	
    return 0;
}
0