結果

問題 No.3456 Common Difference is D
コンテスト
ユーザー hikikomori
提出日時 2026-02-19 14:11:54
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 585 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 317 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 102,804 KB
最終ジャッジ日時 2026-02-28 13:08:44
合計ジャッジ時間 3,441 ms
ジャッジサーバーID
(参考情報)
judge7 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline
import collections
def solve():
    N, D = map(int, input().split())
    A = list(map(int, input().split()))
    
    right_cnt = collections.Counter(A)
    left_cnt= collections.Counter()
    ans = 0
    
    for x in A:
        right_cnt[x] -= 1
        val_i = x - D
        val_k = x + D

        count_i = left_cnt[val_i]
        count_k = right_cnt[val_k]
        
        if count_i > 0 and count_k > 0:
            ans += count_i * count_k
            
        left_cnt[x] += 1
    print(ans)

if __name__ == "__main__":
    solve()
0