| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1287040 | ecen30 | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
//TEsting AI COde
#include <iostream>
#include <vector>
#include <algorithm>
// 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;
}
// Function to construct a mountain range that produces at least K mythical triples
std::vector<int> construct_range(int M, int K) {
// Try to create a range with many mythical triples. We use a pattern that repeats
// numbers in such a way to increase the likelihood of matching distances.
std::vector<int> H;
// Strategy: Create a simple increasing-decreasing pattern
for (int i = 1; i <= M - 2; ++i) {
H.push_back(i);
}
H.push_back(M - 1); // The last peak at height M-1
// For Part II, we might not know the exact number of mythical triples, but we try
// to generate a range that has a reasonable number of them.
return H;
}
int main() {
int part;
std::cin >> part;
if (part == 1) {
// Part I: Count mythical triples
int N;
std::cin >> N;
std::vector<int> H(N);
for (int i = 0; i < N; ++i) {
std::cin >> H[i];
}
long long result = count_triples(H);
std::cout << result << std::endl;
} else if (part == 2) {
// Part II: Construct a mountain range with at least K mythical triples
int M, K;
std::cin >> M >> K;
std::vector<int> range = construct_range(M, K);
std::cout << range.size() << std::endl;
for (int i = 0; i < range.size(); ++i) {
std::cout << range[i] << " ";
}
std::cout << std::endl;
}
return 0;
}
