| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1287037 | ecen30 | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
//Testing AI code
#include <vector>
#include <algorithm>
#include <iostream>
// Function to count the mythical triples
long long count_triples(std::vector<int>& H) {
int N = H.size();
long long mythical_triples = 0;
// Iterate over all triplets (i, j, k)
for (int i = 0; i < N - 2; ++i) {
for (int j = i + 1; j < N - 1; ++j) {
for (int k = j + 1; k < N; ++k) {
// Calculate pairwise distances
std::vector<int> distances = { j - i, k - i, k - j };
std::vector<int> heights = { H[i], H[j], H[k] };
// Sort both distances and heights
std::sort(distances.begin(), distances.end());
std::sort(heights.begin(), heights.end());
// If they match, it's a mythical triple
if (distances == heights) {
mythical_triples++;
}
}
}
}
return mythical_triples;
}
int main() {
// Input the height array (Example: you can modify it as needed)
std::vector<int> H = {4, 1, 4, 3, 2, 6, 1};
// Part I - Count mythical triples
long long result = count_triples(H);
// Output the number of mythical triples
std::cout << result << std::endl;
return 0;
}
