| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1364428 | activedeltorre | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
#include "triples.h"
#include <cassert>
#include <cstdio>
#include <vector>
using namespace std;
long long count_triples(std::vector<int> H)
{
int n=H.size(),hmax=0,z;
for(int i=1; i<=n; i++)
{
hmax=max(hmax,H[i-1]);
}
int cnt=0;
for(int i=1; i<=n; i++)
{
j=i-H[i-1];
if(j>=1)
{
z=j+H[j-1];
if(z+H[z-1]==i)
{
cnt++;
}
}
}
return cnt;
}