提出 #70459841


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, c, a[1000005], b[1000005], cnt[1000005], d[2000005], s[2000005], f[1000005], e[1000005];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m >> c;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int u = 0;
	for (int i = 0; i < n; ) {
		int j = i;
		while (j < n && a[j] == a[i]) {
			j++;
		}
		b[u] = a[i];
		cnt[u] = j - i;
		u++;
		i = j;
	}
	for (int i = 0; i < u; i++) {
		d[i] = cnt[i];
		d[i + u] = cnt[i];
	}
	s[0] = 0;
	for (int i = 0; i < 2 * u; i++) {
		s[i + 1] = s[i] + d[i];
	}
	for (int k = 0; k <= u; k++) {
		ll t = s[k] + c, l = k + 1, r = 2 * u, j = 2 * u;
		while (l <= r) {
			int mid = l + (r - l) / 2;
			if (s[mid] >= t) {
				j = mid;
				r = mid - 1;
			} else {
				l = mid + 1;
			}
		}
		f[k] = s[j] - s[k];
	}
	e[0] = b[0];
	for (int k = 1; k < u; k++) {
		e[k] = b[k] - b[k - 1];
	}
	e[u] = m - b[u - 1];
	long long ans = 0;
	for (int k = 0; k <= u; k++) {
		ans += e[k] * f[k];
	}
	cout << ans;
	return 0;
}

提出情報

提出日時
問題 D - On AtCoder Conference
ユーザ a_little_cat
言語 C++ 20 (gcc 12.2)
得点 425
コード長 1119 Byte
結果 AC
実行時間 104 ms
メモリ 38680 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 2
AC × 32
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3452 KiB
example_01.txt AC 1 ms 3424 KiB
hand_00.txt AC 37 ms 7436 KiB
hand_01.txt AC 37 ms 7400 KiB
hand_02.txt AC 104 ms 38680 KiB
hand_03.txt AC 21 ms 7420 KiB
hand_04.txt AC 1 ms 3456 KiB
hand_05.txt AC 1 ms 3468 KiB
random_00.txt AC 35 ms 7344 KiB
random_01.txt AC 35 ms 7448 KiB
random_02.txt AC 38 ms 7320 KiB
random_03.txt AC 53 ms 9184 KiB
random_04.txt AC 55 ms 10096 KiB
random_05.txt AC 54 ms 9264 KiB
random_06.txt AC 75 ms 25332 KiB
random_07.txt AC 74 ms 24908 KiB
random_08.txt AC 78 ms 23580 KiB
random_09.txt AC 42 ms 7420 KiB
random_10.txt AC 38 ms 7404 KiB
random_11.txt AC 40 ms 7540 KiB
random_12.txt AC 40 ms 7384 KiB
random_13.txt AC 49 ms 7548 KiB
random_14.txt AC 48 ms 7384 KiB
random_15.txt AC 41 ms 7536 KiB
random_16.txt AC 56 ms 7528 KiB
random_17.txt AC 56 ms 7532 KiB
random_18.txt AC 44 ms 9864 KiB
random_19.txt AC 63 ms 9752 KiB
random_20.txt AC 62 ms 9320 KiB
random_21.txt AC 76 ms 24904 KiB
random_22.txt AC 85 ms 23092 KiB
random_23.txt AC 100 ms 35904 KiB