Triple Peaks

면접 대비

시간 제한2초메모리 제한2048 MB

요약
세 봉우리의 높이 세 개가 세 쌍 사이의 거리와 순서를 무시하고 일치하는 삼중항의 개수를 센다.
난이도

어려움10점 중 8점

유형
배열, 수학, 조합론, 구현
정답자
아직 제출이 없습니다

문제

The Cordillera Oriental is a mountain range in the Andes that stretches across Bolivia. It consists of a sequence of NN mountain peaks, numbered from 00 to N−1N - 1. The height of peak ii (0≤i<N0 \leq i < N) is H\[i]H\[i], which is an integer between 11 and N−1N - 1, inclusive.

For any two peaks ii and jj where 0≤i<j<N0 \leq i < j < N, the distance between them is defined as d(i,j)=j−id(i, j) = j - i.

According to ancient Inca legends, a triple of peaks is mythical if it has the following special property: the heights of the three peaks match their pairwise distances ignoring the order.

Formally, a triple of indices (i,j,k)(i, j, k) is mythical if

  • 0≤i<j<k<N0 \leq i < j < k < N, and
  • the heights (H\[i],H\[j],H\[k])(H\[i], H\[j], H\[k]) match the pairwise distances (d(i,j),d(i,k),d(j,k))(d(i,j), d(i,k), d(j,k)) ignoring the order. For example, for indices 0,1,20, 1, 2 the pairwise distances are (1,2,1)(1, 2, 1), so the heights (H\[0],H\[1],H\[2])=(1,1,2)(H\[0],H\[1],H\[2]) = (1,1,2), (H\[0],H\[1],H\[2])=(1,2,1)(H\[0],H\[1],H\[2]) = (1,2,1), and (H\[0],H\[1],H\[2])=(2,1,1)(H\[0],H\[1],H\[2]) = (2,1,1) all match them, but the heights (H\[0],H\[1],H\[2])=(1,2,2)(H\[0], H\[1], H\[2])=(1,2,2) do not match them.

This problem consists of two parts, with each subtask associated with either Part I or Part II. You may solve the subtasks in any order. In particular, you are not required to complete all of Part I before attempting Part II.

예제

이 문제는 공개된 예제가 없습니다.