結果

問題 No.3456 Common Difference is D
コンテスト
ユーザー ID 21712
提出日時 2026-04-20 00:15:00
言語 Go
(1.26.1)
コンパイル:
env GOCACHE=/tmp go build _filename_
実行:
./Main
結果
AC  
実行時間 528 ms / 2,000 ms
コード長 361 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,214 ms
コンパイル使用メモリ 282,920 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2026-04-20 00:15:20
合計ジャッジ時間 16,075 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package main

import . "fmt"

func main() {
	var n,d int
	Scan(&n,&d)
	a := make([]int, n)
	for i := range a {
		Scan(&a[i])
	}
	
	ans := 0
	
	m1 := map[int]int{}
	m2 := map[int]int{}
	
	for i := range a {
		j := len(a)-1-i
		aj := a[j]
		if c, ok := m2[aj+d]; ok {
			ans += c
		}
		if c, ok := m1[aj+d]; ok {
			m2[aj] += c
		}
		m1[aj]++
	}
	
	Println(ans)
}
0