結果

問題 No.3456 Common Difference is D
コンテスト
ユーザー rinrion
提出日時 2026-02-28 15:05:18
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,513 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,452 ms
コンパイル使用メモリ 260,472 KB
実行使用メモリ 32,948 KB
最終ジャッジ日時 2026-02-28 15:05:27
合計ジャッジ時間 6,754 ms
ジャッジサーバーID
(参考情報)
judge4 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vp = vector<pair<int, int>>;

#define rep(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define repr(i, s, n) for (int i = (s); i >= (int)(n); --i)
#define sz(x) ((int)(x).size())

constexpr int INFI = 1001001001;
constexpr ll INFL = (1LL << 60);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, d;
	cin >> n >> d;
	ll ans = 0;
	unordered_map<int, vi> mp;
	map<int, int> cnt;
	vi b;
	vi aa(n);
	rep(i, 0, n){
		cin >> aa[i];
		cnt[aa[i]] ++;
		if(cnt[aa[i]] == 1) b.push_back (aa[i]);
	}

	// cerr <<"cnt:\n";
	// for (auto x: cnt) {cerr <<"("<< x.first <<","<< x.second <<")";} cerr << "\n" ;

	rep(i, 0, sz(b)){
		int a = b[i];
		mp[a].push_back (a);

		if(a >= d){
			mp[a - d].push_back (a);
		}
		if(a >= d + d){
			int add = a - d - d;
			mp[add].push_back (a);
			if(sz(mp[add]) == 3){
				ans += cnt[a] * cnt[a - d] * cnt[add];
				mp[add][0] = mp[add][1];
				mp[add][1] = mp[add][2];
				mp[add].pop_back();
				// cerr <<"a: "<< a << " a - d: "<< a - d << " add: "<< add << "\n" ;
				// cerr <<"cnt[a]: "<< cnt[a] << " cnt[a - d]: "<< cnt[a - d] << " cnt[add]: "<< cnt[add] << "\n" ;
			}
			// cerr <<"mp[a - d - d]:\n";
			// for (auto x: mp[a - d - d]) {cerr << x <<" ";} cerr << "\n" ;
		}
	}
	cout << ans << endl;
	
	return 0;
}
0