結果
| 問題 | No.3456 Common Difference is D |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-28 14:05:26 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 512 ms / 2,000 ms |
| コード長 | 439 bytes |
| 記録 | |
| コンパイル時間 | 3,768 ms |
| コンパイル使用メモリ | 344,856 KB |
| 実行使用メモリ | 28,800 KB |
| 最終ジャッジ日時 | 2026-02-28 14:05:34 |
| 合計ジャッジ時間 | 7,884 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge7 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n, d;
cin >> n >> d;
map<int, ll> l, r;
vector<int> a(n);
rep(i, n) cin >> a[i];
rep(i, n) {
r[a[i]]++;
}
ll ans = 0;
rep(i, n) {
r[a[i]]--;
ans += l[a[i] - d] * r[a[i] + d];
l[a[i]]++;
}
cout << ans << endl;
return 0;
}