| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1290817 | ecen30 | 3개의 봉우리 (IOI25_triples) | C++20 | 0 ms | 0 KiB |
//testing AI Code
#include <vector>
#include <algorithm>
using namespace std;
long long count_triples(const vector<int>& H) {
int N = (int)H.size();
long long result = 0;
// For all possible distances d (between peaks, must be at least 1)
for (int d = 1; 2 * d < N; ++d) {
// Triples: (i, i + d, i + 2d)
for (int i = 0; i + 2 * d < N; ++i) {
int j = i + d, k = j + d;
int a = H[i], b = H[j], c = H[k];
vector<int> heights = {a, b, c};
vector<int> dists = {d, d, 2 * d};
sort(heights.begin(), heights.end());
sort(dists.begin(), dists.end());
if (heights == dists)
result++;
}
}
// Now, for all possible pairs (i, k) where i < k, k-i=d1+d2,
// j = i + d1, 1 <= d1 <= d2 < N, distinct heights: permute and check.
// But the above loop is the dominant pattern since all distances must add up properly, so it's fast.
return result;
}
