結果

問題 No.1233 割り切れない気持ち
ユーザー QCFiumQCFium
提出日時 2019-07-31 00:52:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,839 ms / 3,153 ms
コード長 1,511 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 179,120 KB
実行使用メモリ 17,456 KB
最終ジャッジ日時 2023-09-04 21:40:52
合計ジャッジ時間 8,726 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,384 KB
testcase_04 AC 4 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 525 ms
5,728 KB
testcase_08 AC 995 ms
6,736 KB
testcase_09 AC 2,139 ms
10,132 KB
testcase_10 AC 2,343 ms
10,428 KB
testcase_11 AC 450 ms
5,212 KB
testcase_12 AC 2,779 ms
11,200 KB
testcase_13 AC 2,839 ms
11,364 KB
testcase_14 AC 2,731 ms
11,192 KB
testcase_15 AC 2,549 ms
11,196 KB
testcase_16 AC 2,645 ms
11,200 KB
testcase_17 AC 16 ms
4,384 KB
testcase_18 AC 2,600 ms
17,456 KB
testcase_19 AC 24 ms
4,384 KB
testcase_20 AC 17 ms
4,384 KB
testcase_21 AC 28 ms
4,384 KB
testcase_22 AC 28 ms
4,384 KB
testcase_23 AC 28 ms
4,380 KB
testcase_24 AC 28 ms
4,384 KB
testcase_25 AC 28 ms
4,384 KB
testcase_26 AC 28 ms
4,380 KB
testcase_27 AC 32 ms
4,380 KB
testcase_28 AC 32 ms
4,384 KB
testcase_29 AC 33 ms
4,384 KB
testcase_30 AC 31 ms
4,388 KB
testcase_31 AC 32 ms
4,380 KB
testcase_32 AC 31 ms
4,384 KB
testcase_33 AC 32 ms
4,388 KB
testcase_34 AC 31 ms
4,380 KB
testcase_35 AC 31 ms
4,384 KB
testcase_36 AC 31 ms
4,380 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 17 ms
4,380 KB
testcase_39 AC 574 ms
9,888 KB
testcase_40 AC 568 ms
9,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::map<int, int> a;
	std::vector<std::tuple<int, int, int64_t> > sum;
	for (int i = 0; i < n; i++) a[ri()]++;
	std::pair<int, int64_t> cur = {0, 0};
	for (auto &i : a) {
		sum.push_back(std::tuple<int, int, int64_t> (i.first, cur.first, cur.second));
		cur.first += i.second;
		cur.second += (int64_t) i.first * i.second;
	}
	
	int cache[801];
	for (int i = 0; i <= 800; i++) cache[i] = -1;
	int64_t ans = 0;
	for (auto &i : a) {
		int64_t res = 0;
		if (i.first <= 800) {
			if (cache[i.first] == -1) {
				cache[i.first] = 0;
				for (auto &j : a) cache[i.first] += (j.first % i.first) * j.second;
			}
			res = cache[i.first];
		} else {
			for (int j = 0; j < 200000; j += i.first) {
				auto low = std::lower_bound(sum.begin(), sum.end(), std::tuple<int, int, int64_t>(j, 0, 0));
				auto high = std::lower_bound(sum.begin(), sum.end(), std::tuple<int, int, int64_t>(j + i.first, 0, 0));
				int64_t xsum = (high == sum.end() ? cur.second : std::get<2>(*high)) -
							   (low == sum.end() ? cur.second : std::get<2>(*low));
				int num = (high == sum.end() ? cur.first : std::get<1>(*high)) -
						  (low == sum.end() ? cur.first : std::get<1>(*low));
				// std::cerr << xsum << " " << num * i.first * (j / i.first) << std::endl;
				res += xsum;
				res -= (int64_t) num * i.first * (j / i.first);
			}
		}
		res *= i.second;
		ans += res;
	}
	std::cout << ans << std::endl;
	
    return 0;
}
0