#include "triples.h"
#include <algorithm>
#include <array>
#include <iterator>
#include <map>
#include <cassert>
long long count_triples(std::vector<int> H) {
int N = H.size();
long long ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i+1; j < N; j++) {
int d = j-i;
int hi = H[i], hj = H[j], hk = H[i] + H[j];
// this is basically just massive casework on the order of hi hj hk :sob:
if (hk < N-1) {
if (hi == hj) {
if (d == hi && (j+hi) < N && H[j+hi] == hk) ++ans;
} else {
if (d == hi) {
if ((j+hj) < N && H[j+hj] == hk) ++ans;
// if so, then we have H[i], H[j], H[j+H[j]]
// H[i] = j-i, so thats good
// H[j] = k-j, so thats good
// H[k] = (k-j) + (j-i) = k-i, so thats good
// now we just spam this logic literally everywhere
}
if (d == hj) {
if ((j+hi) < N && H[j+hi] == hk) ++ans;
}
}
}
if (hj > hi) {
hk = hj - hi;
if (d == hi && (j+hk) < N && H[j+hk] == hk) ++ans;
if (d == hk && (j+hi) < N && H[j+hi] == hk) ++ans;
}
if (hi > hj) {
hk = hi - hj;
if (d == hj && (j+hk) < N && H[j+hk] == hk) ++ans;
if (d == hk && (j+hj) < N && H[j+hj] == hk) ++ans;
}
}
}
return ans;
}
std::vector<int> construct_range(int M, int K) {
std::vector<int> ans;
ans.push_back(1);
ans.push_back(1);
for (int i = 2; i < M; i++) {
ans.push_back(i);
}
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... |