結果

問題 No.3128 Isosceles Triangle
ユーザー vjudge1
提出日時 2025-04-28 20:23:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 338 ms / 2,500 ms
コード長 538 bytes
コンパイル時間 2,467 ms
コンパイル使用メモリ 203,484 KB
実行使用メモリ 16,776 KB
最終ジャッジ日時 2025-04-28 20:24:00
合計ジャッジ時間 8,253 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |                 scanf("%d",&x);
      |                 ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const int MAX=1e7+10;
int main()
{
	int n,i,x;
	ll ans,cnt;
	scanf("%d",&n);
	map<int,int> mp;
	vector<int> res;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		mp[x]++;
		res.push_back(x);
	}
	sort(res.begin(),res.end());
	ans=0;
	for(auto &it:mp)
	{
		cnt=lower_bound(res.begin(),res.end(),it.first*2)-res.begin();
		cnt-=it.second;
		ans+=cnt*(it.second*(it.second-1)/2);
	}
	printf("%lld\n",ans);
	return 0;
}
0