# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1252178 | bzzzzzzzzzz | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "triples.h"
using namespace std;
using ll = long long;
long long count_triples(vector<int> H) {
int n = (int)H.size();
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int k = i + 2; k < n; k++) {
int x = k - i;
if (x == H[i]) {
if (H[k] < x) {
if (H[i + H[k]] == x - (i + H[k])) {
ans++;
}
if (i + H[k] + H[k] != k && H[k - H[k]] == (k - H[k]) - x) {
ans++;
}
}
} else if (x == H[k]) {
if (H[i] < x) {
if (H[i + H[i]] == x - (i + H[i])) {
ans++;
}
if (i + H[i] + H[i] != k && H[k - H[i]] == (k - H[i]) - x) {
ans++;
}
}
} else {
if (H[i] + H[k] == x) {
if (H[i + H[i]] == x) {
ans++;
}
if (i + H[i] + H[i] != k && H[i + H[k]] == x) {
ans++;
}
}
}
}
}
return ans;
}