結果

問題 No.3128 Isosceles Triangle
ユーザー eve__fuyuki
提出日時 2025-05-13 21:24:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 329 ms / 2,500 ms
コード長 671 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 205,028 KB
実行使用メモリ 20,724 KB
最終ジャッジ日時 2025-05-13 21:24:54
合計ジャッジ時間 8,293 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void fast_io() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
}

int main() {
	fast_io();
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> cnt;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	vector<int> nums;
	vector<long long> cnts{0};
	for (auto [num, count] : cnt) {
		nums.push_back(num);
		cnts.push_back(count + cnts.back());
	}
	long long ans = 0;
	for (int i : nums) {
		if (cnt[i] < 2) {
			continue;
		}
		auto it = lower_bound(nums.begin(), nums.end(), i + i);
		long long res = cnts[it - nums.begin()] - cnt[i];
		ans += res * cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans << "\n";
}
0