結果
| 問題 | No.3456 Common Difference is D |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-28 13:54:57 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 239 ms / 2,000 ms |
| コード長 | 535 bytes |
| 記録 | |
| コンパイル時間 | 3,408 ms |
| コンパイル使用メモリ | 349,456 KB |
| 実行使用メモリ | 16,768 KB |
| 最終ジャッジ日時 | 2026-02-28 13:55:03 |
| 合計ジャッジ時間 | 5,757 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#include<atcoder/math>
using namespace atcoder;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,D;
cin>>N>>D;
vector<ll> A(N);
map<ll,ll> M;
for(int i=0;i<N;i++){
cin>>A[i];
M[A[i]]++;
}
map<ll,ll> P;
ll an=0;
for(int i=0;i<N;i++){
M[A[i]]--;
if(P.count(A[i]-D)&&M.count(A[i]+D)){
an+=P[A[i]-D]*M[A[i]+D];
}
P[A[i]]++;
}
cout<<an<<"\n";
}