# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1250642 | Cebrayil09 | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
#include "triple.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long count_triples(vector<int> h) {
ll cnt = 0;
for(int i = 0;i < h.size();i++) {
int j = -1, k = -1;
if(h[i] <= i) {
int jn = i - h[i];
int kn = jn + h[jn];
if(h[kn] == i - kn) {
cnt++;
j = jn;
k = kn;
}
kn = i - h[jn];
if(h[kn] == kn - jn) {
if(j != jn || k != kn) {
cnt++;
}
}
}
}
return cnt;
}