ai - bj = i - j를 ai - i = bj - j 로 치환시켜 dictionary에 저장 후 조합의 수만큼 더해줌.
import sys
input = sys.stdin.readline
from collections import defaultdict
for test in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
new_arr = defaultdict(int)
for idx, num in enumerate(arr):
new_arr[num - idx] += 1
answer = 0
for num in new_arr:
k = new_arr[num]
answer += k * (k - 1) // 2
print(answer)
'practivceAlgorithm > codeforce' 카테고리의 다른 글
[Codeforce][Python] #702 A.Dense Array (0) | 2021.11.07 |
---|---|
[codeforce][Python] #719 E.Arranging The Sheep (0) | 2021.10.17 |
[codeforce][Python] #719 C.Not Adjacent Matrix (0) | 2021.10.17 |
[codeforce][Python] #719 B.Ordinary Numbers (0) | 2021.10.17 |
[codeforce][Python] #719 A.Do Not Be Distracted! (0) | 2021.10.17 |