#include "triples.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
vector<int> construct_range(int M, int K) {
ll N = M;
vector<int> vf;
vf.push_back(1);
for (ll i=1;i<N;i++) {
vf.push_back(i);
}
return vf;
}
long long count_triples(vector<int> H) {
ll N = H.size();
ll ans = 0;
//H[x]=z-x H[y]=z-y H[z]=y-x
for (ll x=0;x<N;x++) {
ll z = x+H[x];
if (z<N) {
ll y=H[z]+x;
if (y<N) {
if ((H[y]+y)==z && x<y && y<z) {
ans++;
}
}
}
}
//H[x]=z-x H[y]=y-x H[z]=z-y
for (ll x=0;x<N;x++) {
ll z = x+H[x];
if (z<N) {
ll y = z-H[z];
if (y>=0) {
if (H[y]==(y-x) && x<y && y<z) {
ans++;
}
}
}
}
//H[x]=y-x, H[y]=z-x, H[z]=z-y
for (ll x=0;x<N;x++) {
ll y=x+H[x];
if (y<N) {
ll z = x+H[y];
if (z<N) {
if (H[z]==(z-y) && x<y && y<z) {
ans++;
}
}
}
}
//H[x]=y-x, H[y]=z-y, H[z]=z-x
for (ll x=0;x<N;x++) {
ll y=x+H[x];
if (y<N) {
ll z = y+H[y];
if (z<N) {
if (H[z]==(z-x) && x<y && y<z) {
ans++;
}
}
}
}
//H[x]=z-y, H[y]=y-x, H[z]=z-x
for (ll y=0;y<N;y++) {
ll x = y-H[y];
if (x>=0) {
ll z = y+H[x];
if (z<N) {
if (H[z]==(z-x) && x<y && y<z) {
ans++;
}
}
}
}
for (ll x=0;x<N;x++) {
for (ll y=(x+1);y<N;y++) {
for (ll z=(y+1);z<N;z++) {
if (H[x]==(z-y) && H[y]==(z-x) && H[z]==(y-x)) {
ans++;
}
}
}
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |