結果

問題 No.1233 割り切れない気持ち
ユーザー rabimearabimea
提出日時 2023-01-25 01:49:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,049 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 207,060 KB
実行使用メモリ 19,936 KB
最終ジャッジ日時 2023-09-08 16:37:14
合計ジャッジ時間 11,515 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
19,936 KB
testcase_01 AC 10 ms
9,616 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 4e5 + 11;
int a[N];
ll cnt[N], sum[N];

int main() {
	ios :: sync_with_stdio(false);
	
	int n; cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
		cnt[a[i]] ++;
		sum[a[i]] += a[i];
	}
	
	for(int i = 1; i < N; i ++) {
		cnt[i] += cnt[i - 1];
		sum[i] += sum[i - 1];
	}
	
	sort(a + 1, a + n + 1);
	ll ans = 0;
	
	map <int, ll> mem;
	for(int i = 1; i <= n; i ++) {
		int x = a[i];
		if(mem.find(x) != mem.end())
			ans += mem[x];
		
		ll tmp = 0;
		for(int j = 0; j + x < N; j += x) {
			ll s = sum[j + x - 1] - (j ? sum[j - 1] : 0);
			ll c = cnt[j + x - 1] - (j ? cnt[j - 1] : 0);
			tmp += s - c * j;
		}
		
		mem[x] = tmp;
		ans += tmp;
	}
	
	cout << ans << '\n';
}
0