結果

問題 No.3456 Common Difference is D
コンテスト
ユーザー Mitsubachi
提出日時 2026-02-28 14:25:30
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 360 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 799 ms
コンパイル使用メモリ 20,832 KB
実行使用メモリ 35,384 KB
最終ジャッジ日時 2026-02-28 14:25:38
合計ジャッジ時間 7,487 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

n,d=map(int,input().split())
a=list(map(int,input().split()))
ans=0
front=defaultdict(int)
back=defaultdict(int)
for i in range(2,n):
    back[a[i]]+=1
front[a[0]]+=1

for i in range(1,n-1):
    if a[i]-d in front and a[i]+d in back:
        ans+=front[a[i]-d]*back[a[i]+d]
    front[a[i]]+=1
    back[a[i+1]]-=1
print(ans)
0