# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1251258 | guymmk | 3개의 봉우리 (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;
int n;
map<vector<int>,int>mp;
int is_triple(vector<int>g){
sort(g.begin(),g.end());
if(mp[g]||(g[0]==g[1]||g[0]==g[2]||g[1]==g[2])||g[0]<0||g[2]>=n)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;
n=v.size();
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
ans+=is_triple({i,j,i+v[i]});
ans+=is_triple({i,j,j+v[i]});
ans+=is_triple({i,j,i+v[j]});
ans+=is_triple({i,j,j+v[j]});
ans+=is_triple({i,j,i-v[i]});
ans+=is_triple({i,j,j-v[i]});
ans+=is_triple({i,j,i-v[j]});
ans+=is_triple({i,j,j-v[j]});
}
}return ans;
}
vector<int> construct_range(int M, int K) {
vector<int>pred;
int mx=0,cnt=50;
srand(time())
while(mx<K&&cnt--){
vector<int>idk(M);
for(auto& i:idk){
i=rand()%M+1
}
int f=count_triples(idk)
if(f>mx){
mx=f;
pred=idk;
}
}return pred;
}