# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1250368 | guymmk | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
#include "triples.h"
using namespace std;
vector<int> v;
map<vector<int>,int>mp;
int is_triple(vector<int>g){
sort(g.begin(),g.end())
if(mp[g])return 0;
mp[g]++;
vector<int>a,b;
a={g[1]-g[0],g[2]-g[0],g[2]-g[1]};
b={v[g[0]],v[g[1]],v[g[2]]};
sort(a.begin(),a.end());
sort(b.begin(),b.end());
return (int)(a==b);
}
long long count_triples(vector<int> hsh) {
v=hsh;
int ans=0;
int n=v.size();
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(v[i]!=j-i){
if(v[i]>j-i)ans+=is_triple({i,j,i+v[i]});
ans+=is_triple({i,j,j+v[i]});
}
if(v[i]!=j-i){
ans+=is_triple({i,j,i+v[j]});
ans+=is_triple({i,j,j+v[j]});
}else if(v[i]==v[j]){
ans+=is_triple({i,j,j+v[j]});
}
}
}return ans;
}
vector<int> construct_range(int M, int K) {
return {1, 1, 1};
}