| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1290838 | ecen30 | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
//testing AI Code
#include <bits/stdc++.h>
using namespace std;
long long count_triples(vector<int> H) {
int N = H.size();
long long ans = 0;
for (int i = 0; i < N; i++) {
int d = H[i]; // want H[i] = k - i
int k = i + d; // implied k
if (k >= N) continue; // out of bounds → not a valid triple
int hk = H[k];
// Two possible choices of j:
// Case 1: hk == x => x = hk => j = i + hk, H[j] must be d - hk
// Case 2: hk == d-x => x = d - hk => j = i + (d-hk), H[j] must be hk
// Case 1:
if (hk > 0 && hk < d) {
int j = i + hk;
if (j > i && j < k) {
if (H[j] == d - hk) ans++;
}
}
// Case 2:
int x2 = d - hk;
if (x2 > 0 && x2 < d) {
int j = i + x2;
if (j > i && j < k) {
if (H[j] == hk) ans++;
}
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int mode;
cin >> mode;
if (mode == 1) { // Part I
int N;
cin >> N;
vector<int> H(N);
for (int i = 0; i < N; i++) cin >> H[i];
cout << count_triples(H) << "\n";
}
else {
// Part II (construction) left empty intentionally
}
return 0;
}
